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 2 of 4.
Reshma Wadhavane said:
9 years ago
An interface is just like a class but difference is that interface contains only final & static variable.
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;).
Java compiler trite it as (public static final int i=30;).
Jithin said:
1 decade ago
This why because if int k=4 in an interface implicitly means
public static final int k=4 ;
public static final int k=4 ;
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers