SCJP Module-4 Question-2


 

SCJP Module-4 Question-2

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

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.

Ads