Java is the future !: Quiz of the Day | November 5, 2010

Friday, November 5, 2010

Quiz of the Day | November 5, 2010

What will be the result of compiling the following programs and executing it using the following command - java Child?


a. Prints 9
b. Compiler error at line 5
c. Compiler error at line 6
d. None of the above



Solution :  Choice C is the correct answer.


You cannot access the protected variable in the Parent class from the Child class using the parent class reference. The Child class does inherit the variable x, but it can be accessed only by an object reference of the Child class. There is no error at line 5. It is legal to refer to a class as packagename.classname even if the package is already imported. So choice B is incorrect.

Source : "Facebook community"

No comments:

Post a Comment