The core Java program given below checks the concepts of Inheritance in core Java and is very useful for SCJP exam also
The core Java program given below checks the concepts of Inheritance in core Java and is very useful for SCJP exam alsoGiven 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"