I have gone through many links about reference object in java. Still I don’t have clear idea.
superclass obj = new subclass();
How will obj get instantiated? What is the use of it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
objis a reference variable whose type issuperclass. That means that such a variable can point to an object of typesuperclassor any of its subclasses. In your case you are instantiating one such subclass, calledsubclassin your example. Now you can call any method on this object that is declared insuperclass—and which thesubclassis guaranteed to possess either by inheriting or by overriding.