1.

Which is correct syntax?(a) classname objectname= new() integer;(b) classname objectname= new classname;(c) classname objectname= new classname();(d) classname objectname= new() classname();I have been asked this question in a national level competition.Question is from Overloading Constructors in division Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (c) classname objectname= new classname();

The best I can explain: The syntax for object CREATING in java with calling a constructor for is it is as in OPTION c. The syntax must CONTAIN the classname FOLLOWED by the object name. The keyword new must be used and then the constructor CALL with or without the parameters as required.



Discussion

No Comment Found

Related InterviewSolutions