Share on Google+Share on Google+

SCJP Module-1 Question-6

The core Java program given below checks the concepts of Inheritance in core Java and is very useful for SCJP exam also

Given a sample code:

1 abstract class Ball {
2 static void method() {
3 int value = 10;
4 System.out.println("value = " + value);
5 }}

6 class Football extends Ball {

7 public class Sample2 {
8 public static void main(String args[]) {
9 Football a = new Football();
10 a.method1();
11 }}

What will be the result?

(1) Compilation succeeds but cause runtime error
(2) Compilation succeeds and give output 10
(3) Compilation fails because of an error at line 2
(4) Compilation succeeds but give warning message because of line no 10


(2), (4)


This sample code compiles and execute successfully with output 10 but with a warning that "The static method method() from the type ball should be accessed in a static way"


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


Advertisement null