
Hi all, Analyse the following java program and guess the output of the program.
import java.lang.*;
import java.util.*;
class StringDemo
class StringDemo
{
public static void main(String args[])
{
String str = null;
String str = null;
str = str+"mbvreddy";
System.out.println("Length of str = "+str.length());
}
}
Please leave ur valuable guesses as the comments and justify ur answer..
6 comments:
hi bhaktha ,
i think this program will print the lenght ,i mean the no.of charecters inthe given word "mvdreddy".
am i correct?
hey "public" key word is need for the class StringDemo to access the PVSM ....
@Manu1
U mean to say that the program will printout 8... is it?
@Manu2
Since we have only one class in this application, public before the class StringDemo is not really needed.
It is printing o/p as 12. So it is taking "null" length also.
It is printing o/p as 12. It means it is printing length including "null".
@ Jittu
Why is it taking Null also in calculating the string value?
What is stored in string?
Post a Comment