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

When should I use abstract classes and when should I use interfaces?

2 Answers  


What are methods of a class?

0 Answers  


What is java util function?

0 Answers  


Why is it called boolean?

0 Answers  


what type of questions asked for barclays technologies pune please send urgent

0 Answers  






What is thread life cycle?

0 Answers  


What does indexof return in java?

0 Answers  


What are the java ide’s?

0 Answers  


Difference between serialization and deserialization in java?

0 Answers  


2) Suppose there are 5 directories having lot of files (say txt files) in each directory. 2 things :- 2.1) You want to search for filenames which have a particular pattern. 2.2) Out of these filtered files you want to search for a particular keyword or a search string. How can you achieve this?

0 Answers   RBS, TCS,


Can we create our own wrapper class in java?

0 Answers  


How do you pass by reference?

0 Answers  


Categories