Compilation error due to 2 reasons. 1. All variables defined in the Interfaces are implicitly public static final. So need not specify "Static" in interface.
2. If any of the member functions of a Interface is not Overriden , a compilation error will be thrown
RE: What is the Output of the following Java Program
Compilation error due to 2 reasons. 1. All variables defined in the Interfaces are implicitly public static final. So need not specify "Static" in interface.
2. If any of the member functions of a Interface is not Overriden a compilation error will be thrown
RE: What is the Output of the following Java Program
Dear All
This will be a compilation error because method some method must be impelemented. Variable x inside interface I1 is fine.. Even we need not have to write static key word for varibale x. Because by default all the variables of interface is public static and final. So in above written example just correct syntex and write method body public void someMethod(); inside class A it will run.
public interface I1 { static String x "inside I1"; public void someMethod(); }
public class A implements I1 {
public static void main(String args[]) { System.out.println("Calling I1 var ..."+I1.x); } public void someMethod() {}; }
RE: What is the Output of the following Java Program
The output will be a compilation error but not because of the static(Static written though.. i ignore) word used but because the abstract method has not been implemented in the class nor has it been declared as abstract.
RE: What is the Output of the following Java Program
The above program gives 2 compilation errors:-
1. the keyword is static and NOT Static. Did you notice the erroneous Capital S.
2. If your class implements an interface which has a method declaration that method has to be defined/implemented within your class or else compilation error will occur.
An interface variable is by default public static final which means its a constant and that it has to be initialized with a value. It doesn't matter whether you use all or either of the three access specifiers.