Java Programming - Java.lang Class - Discussion
Discussion Forum : Java.lang Class - Finding the output (Q.No. 18)
18.
What will be the output of the program?
interface Foo141
{
int k = 0; /* Line 3 */
}
public class Test141 implements Foo141
{
public static void main(String args[])
{
int i;
Test141 test141 = new Test141();
i = test141.k; /* Line 11 */
i = Test141.k;
i = Foo141.k;
}
}
Answer: Option
Explanation:
The variable k on line 3 is an interface constant, it is implicitly public, static, and final. Static variables can be referenced in two ways:
Via a reference to any instance of the class (line 11)
Via the class name (line 12).
Discussion:
4 comments Page 1 of 1.
Noorshid said:
10 years ago
What is about line 13?
Urvashi said:
9 years ago
It is local. So we have to initialize it. We can't use it directly.
Sun said:
8 years ago
I think it's because the static usage of Interfaces is the same as classes.
Thirumurugan said:
6 years ago
Does interface can has constant? Explain
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers