SCJP Module-2 Question-10

This program heps in understating of methods and also gives the knowledge of hoe the methods can be called.

 
 

Share on Google+Share on Google+

SCJP Module-2 Question-10

Ads

This program heps in understating of methods and also gives the knowledge of hoe the methods can be called.

What is the output of the following code:

public class Example10 {
public static void main(String[] argv) {
SubExample2 se = new SubExample2();
se.showTitle();

}
}

class SubExample1{
String Name;

public SubExample1(String n) {
Name = n;
}

public void showName() {
System.out.println("Name is " + Name);
}
}

class SubExample2 extends SubExample1 {
public void setName(String nn) {
Name = nn;
}
}

What is the output of the above given code :

1  n

2. nn

3. null

4. Unresolved compilation problem:

Answer :

(4)

Explanation :

Since constructor of the SubExample1 class has a parameterized constructor that's why the "Name" value is undefined in this case.

Advertisements

Ads

Posted on: July 8, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles