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 1 of 4.

Jithin said:   1 decade ago
This why because if int k=4 in an interface implicitly means
public static final int k=4 ;

Viper5073 said:   1 decade ago
Interface contain only abstract methods.

Mohd Shahid Arafat said:   1 decade ago
Interface has provide 100% of abstraction method.

Avinash said:   1 decade ago
Interface Contains only abstract methods. Then it has to be declared as abstract. Therefore, we might even get option 4.

Sandip said:   1 decade ago
What is abstract method?

Avi_7v said:   1 decade ago
A method which doesn't have the body is called as abstract method.

Meena said:   1 decade ago
Interface contain only abstract methods.

Vishal said:   1 decade ago
Why public, static, final is only used in interface method?

Nikhil said:   1 decade ago
Why public, static, final is only used in interface method?
>> Because if you try to define other access modifier then you will get the compile time exception.

Sandeep said:   1 decade ago
Interface contains only abstract methods in it so no need of again declaring as abstract. And protected used for inheritance relationship.


Post your comments here:

Your comments will be displayed after verification.