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?
- final int k = 4;
- public int k = 4;
- static int k = 4;
- abstract int k = 4;
- volatile int k = 4;
- protected int k = 4;
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.
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.
>> 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.
Viper5073 said:
1 decade ago
Interface contain only abstract methods.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers