This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overiding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overiding" Watch "Overiding" New topic
Author

Overiding

kantu Deshpande
Greenhorn

Joined: Sep 29, 2000
Posts: 13
public class Parent {
private void print(){
System.out.println(" From Parent");
}
public static void main(String args[]){
Parent p1 = new Parent();
p1.print();
p1 = new Chield();
p1.print();
}
}
class Chield extends Parent{
public void print(){
System.out.println(" From chield");
}
}
Output will be:
A. Compile error can't override the private method print()
B. From Parent
From chield
C. From Parent
From Parent
D. From chield
From chield
Given ans : C
If you instantiate two objects with same name as we did in this (p1) what happnes to the first reference object?..Please let me know..
Thanks,
Kantu..

Ramesh Donnipadu
Ranch Hand

Joined: Sep 16, 2000
Posts: 100
Kanthu,
It becomes eligible for garbage collection. We lose reference to the object.
 
GeeCON Prague 2014
 
subject: Overiding