SCJP Module-6 Question-19


 

SCJP Module-6 Question-19

The Program given below will test your understanding about the Inheritance and Object Initialization in Java.

The Program given below will test your understanding about the Inheritance and Object Initialization in Java.

Given below the sample code :

1  class mainClass {
2  void process() throws Exception {
3  throw new Exception();
4  }}
5  class sub extends mainClass {
6  void process() {
7  System.out.println("sub class");
8  }}
9  class except {
10 public static void main(String[] args) {
11 mainClass m = new sub();
12 m.process();
13 }}

How can we correct the above code without changing the class's definiton ?

1. No need of correction

2. By adding 'static' to class at line number 1 & 5

3. By creating object of 'sub' at line 11 and  use it at line 12.

4. It can't be correct.

Answer

(3)

Ads