is it mandatory to deaclare all variables public static
fianl in interfaces?if i declare like in the below program,
public interface A
{
public static final int I=0;
int j=0;
}
in interface A,what is the difference between I,j?

Answers were Sorted based on User's Feedback



is it mandatory to deaclare all variables public static fianl in interfaces?if i declare like in t..

Answer / sreedhar a

As per interface definition all the member variables by
default are public static final. There is no difference
between I and j variables. JVM will consider the j variable
as public static final int j=0;
Note: variables declared in interface must be initialized
otherwise program will fail to compile.

Is This Answer Correct ?    7 Yes 0 No

is it mandatory to deaclare all variables public static fianl in interfaces?if i declare like in t..

Answer / ramakrishna

generally if we want to access the variables(non-static)
which are present in the class we use the reference of that
class. we get the reference of the class after creation of
the object. but we can not able to create the object of the
interface if we define the non-static variables inside the
interface if we want to access it is not possible so if we
want to define the variables we should have to define the
variables as static.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Why we override equals() method?

0 Answers  


Why super is first line in java?

0 Answers  


How 'java' got its name and what it stands for?

11 Answers   Wipro,


What is the disadvantage of java?

0 Answers  


What is a java developer salary?

0 Answers  


When the constructor of a class is invoked?

0 Answers  


What is string value?

0 Answers  


How does sublist works in java?

0 Answers  


How can you write a loop indefinitely in java programming?

0 Answers  


How is Object Oriented Programming different from Procedure Oriented Programming?

0 Answers   Amdocs,


Can we convert list to set in java?

0 Answers  


What happens when you invoke a thread’s interrupt method while it is sleeping or waiting?

0 Answers  


Categories