Home Tutorial Java Scjp Part6 SCJP Module-6 Question-19

 
 

SCJP Module-6 Question-19
Posted on: July 15, 2010 at 12:00 AM
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)

Related Tags for SCJP Module-6 Question-19:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.