Home Tutorial Java Scjp Part4 SCJP Module-4 Question-14

 
 

Share on Google+Share on Google+
SCJP Module-4 Question-14
Posted on: July 10, 2010 at 12:00 AM
Advertisement
The program given below checks you knowledge of function and constructor in core Java and it is very helpful for SCJP exam preparation.

Given below the sample code :

class Superclass {
int i = 30;
public void function()
{
System.out.println("Superclass.function()");
}
Superclass()
{
function();
}
}
public class Subclass extends Superclass
{
int i = -1;
public static void main(String argv[])
{
Superclass b = new Subclass();
System.out.println(b.i);
b.function();
}
public void function()
{
System.out.println("Subclass.function()");
}
}

What will be the output of the following code ?

1. Subclass.function()   Subclass.function()

2. Subclass.function()   -1    Subclass.function()

3. Subclass.function()    30   Subclass.function()

4. Compile error

Answer :

(30)

Advertisement

Related Tags for SCJP Module-4 Question-14:


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 10, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com