Home Tutorial Java Scjp Part2 SCJP Module-2 Question-10

 
 

Share on Google+Share on Google+
SCJP Module-2 Question-10
Posted on: July 8, 2010 at 12:00 AM
Advertisement
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.

Advertisement

Related Tags for SCJP Module-2 Question-10:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 8, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com