Java Programming - Language Fundamentals - Discussion

Discussion Forum : Language Fundamentals - General Questions (Q.No. 7)
7.
public interface Foo 
{ 
    int k = 4; /* Line 3 */
}
Which three piece of codes are equivalent to line 3?
  1. final int k = 4;
  2. public int k = 4;
  3. static int k = 4;
  4. abstract int k = 4;
  5. volatile int k = 4;
  6. protected int k = 4;
1, 2 and 3
2, 3 and 4
3, 4 and 5
4, 5 and 6
Answer: Option
Explanation:

(1), (2) and (3) are correct. Interfaces can have constants, which are always implicitly public, static, and final. Interface constant declarations of public, static, and final are optional in any combination.

Discussion:
31 comments Page 2 of 4.

Md Mahbubur Rahman said:   10 years ago
Interface are public, static & final.

Archana said:   1 decade ago
Answer is A because interface contain an abstract method.

Chandini said:   1 decade ago
In 1.8 version Interfaces support default implementations also.

Bat said:   1 decade ago
Interfaces can have constants, constants in java are public, static, final.

Amit said:   1 decade ago
Any variables you write in interface like (int i=30;).

Java compiler trite it as (public static final int i=30;).

Amit said:   1 decade ago
All the methods in interface are by default public and static. And the variables are public static final.

A C Department said:   1 decade ago
"Interfaces can have constants, which are always implicitly public, static, and final. Interface constant declarations of public, static, and final are optional in any combination ".

Who can get it instantly? Please give examples w/description, not only theories.

Sauravkumararya said:   1 decade ago
Abstract keyword will be not apply for variable. It is applicable only for methods, class.

Trupti said:   1 decade ago
By default in interface all the members are public, static and final.

Dileep Kumar M B said:   1 decade ago
Static means the variable is not belonging to any specific class. It can be accessible without creating an object. (can also be accessed along with the class name). And static methods cannot be overridden by non-static methods.

Non-static variables cannot be accessed in static methods (context).


Post your comments here:

Your comments will be displayed after verification.