Share on Google+Share on Google+

SCJP Module-6 Question-19

Advertisement
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)

Advertisements

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