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

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).

Ann said:   1 decade ago
What is static in java ?

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.

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.

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

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

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

Sandip said:   1 decade ago
What is abstract 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.

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


Post your comments here:

Your comments will be displayed after verification.