This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inheritence" Watch "inheritence" New topic


paramasivam Ramu
Ranch Hand

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

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

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

output is :

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

Joined: Jan 16, 2005
Posts: 45

SCJP 1.4<br />SCWCD 1.4
It is sorta covered in the JavaRanch Style Guide.
subject: inheritence
Similar Threads
Regd. constructor chaining
Mock exam question
Overloading,Overriding, Runtime Type
Why private method of parent is called?