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

Explain the importance of finally over return statement?

0 Answers  


Can you override a private or static method in java?

1 Answers  


Can you override static method in java?

1 Answers  


Difference between throw and throws?

0 Answers  


what are the oops concept in java explain with real time examples

24 Answers   Accenture, Bosch, Consummate Technologies, CTS, Current Technologies, iNautix, Infosys, Kekran Mekran, QA InfoTech, RTRT, SofTech, Tech Mahindra, Thorogood, Timios, Wipro,






Break statement can be used as labels in java?

0 Answers  


What is fundamental datatype?

0 Answers  


What are encapsulation, inheritance and polymorphism?

0 Answers  


How do you execute a thread in java?

0 Answers  


Is intellij better than eclipse?

0 Answers  


What is a ternary operator in java? What is an interface?

0 Answers  


What is int argc char * argv?

0 Answers  


Categories