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"
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.