Share on Google+Share on Google+

SCJP Module-4 Question-14

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)

Advertisements

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

Share this Tutorial 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.