1.

How to declare an object of class String?(a) String object_Name = value;(b) String object_name = new;(c) String object_name= new value;(d) String object_name= value new;I have been asked this question in an interview for job.My query is from String Class in portion Inbuilt Classes of Object Oriented Programming

Answer»

The CORRECT ANSWER is (a) String object_Name = value;

The best I can explain: The class name String is given. And then the object name is mentioned. There are two ways to declare and INITIALIZE the string. Either by giving direct string value or by using new keyword. But if new operator is used, CONSTRUCTOR of String class have to be called. From the given options, the direct string value declaration is correct.



Discussion

No Comment Found

Related InterviewSolutions