File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inheritence 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 "inheritence" Watch "inheritence" New topic
Author

inheritence

paramasivam Ramu
Ranch Hand

Joined: Mar 30, 2005
Posts: 39
hi,
Explain me below code.


class Phone {
String device = "Phone.device";
void showDevice() {
System.out.println("Phone.showDevice," + device + " ");
}
Phone() {
System.out.println("Phone construtor");
showDevice();
System.out.println("Phone construtor end");
}
}

class Mobile extends Phone {
String device = "Mobile.device";
void showDevice() {
System.out.println("Mobile.showDevice," + device + " ");
}
Mobile() {
showDevice();
}
public static void main(String[] args) {
Phone n = new Mobile();
n.showDevice();
}
}

output is :

Phone construtor
Mobile.showDevice,null//why Mobile device is called?why it prints null?
Phone construtor end
Mobile.showDevice,Mobile.device
Mobile.showDevice,Mobile.device
Mohana Priya
Ranch Hand

Joined: Jan 16, 2005
Posts: 45


SCJP 1.4<br />SCWCD 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inheritence