Share on Google+Share on Google+

SCJP Module-4 Question-2

Advertisement
The given example checks you concept of method overriding in Java and help you in understanding of overriding concept in Java.

Given the following sample code:

class Example2 {

void Twin(int x, float y) { }

}

class SubExample2 extends Example2{
public void Twin(int x, float y) { }
}

Is the following code correct ,with same name methods with same number of arguments ? Choose correct option :

1. Correct code , method overriding is used.

2. Methods can't have the same name.

3. Methods can have same name but arguments must be different.

4. Will throw Exception.

Answer :

(1)

Explanation :

In this code , method overriding is used. In method overriding , method of super class with same name & same number of arguments ,can be used in  subclasses.

Advertisements

Posted on: July 9, 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.