Examveda
Examveda

What will be the output for the below code?
public interface TestInf{
      int i =10;
}

public class Test{
      public static void main(String... args){
            TestInf.i=12;
	    System.out.println(TestInf.i);
      }
}

A. Compile with error

B. 10

C. 12

D. Runtime Exception

E. None of these

Answer: Option A

Solution(By Examveda Team)

All the variables declared in interface is implicitly static and final , therefore can't change the value.


This Question Belongs to Java Program >> Interfaces And Abstract Classes

Join The Discussion

Comments ( 1 )

  1. Sailaja Vishnubhatla
    Sailaja Vishnubhatla :
    4 years ago

    But class test did not implement interface testinf.

Related Questions on Interfaces and Abstract Classes

What is an interface in Java?

A. A contract specifying a set of methods that a class must implement

B. A class that cannot be instantiated

C. A class that contains only static methods

D. A subclass of the Object class