Share on Google+Share on Google+

SCJP Module-4 Question-15

The program given below tests your understanding of inheritance and, function overloading and function overriding in Java.

Given below the sample code :

class SuperClass1
private void m1()
System.out.println("SuperClass's m1()");
public void m2()
System.out.println("SuperClass's m2()");
class Modify extends Superclass
public void m1()
System.out.println("Modify's method1()");
public static void main(String args[])
SuperClass1 s = new Modify();

What will be the output of the following :

1. Prints : SuperClass's m1()

2. Prints : SuperClass's m2()

3. Error in compilation.

4.  Prints : SuperClass's m1()  SuperClass's m2()

Answer :


Explanation :

Type mismatch: cannot convert from Modify to SuperClass1.



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.