Impetus Interview Questions: Code Snipet 1
What will be the output of the code?
interface TestOne{
int limit=100;
void display();
}
interface TestTwo{
int limit=200;
void display();
}
public class TestInterface implements TestOne,TestTwo{
//int limit=0;
@Override
public void display() {
System.out.println("Hello... Test interface...."+limit);
}
public static void main(String [] arg){
TestInterface obj=new TestInterface();
obj.display();
}
}
-------------------------------------------
Output: Compiler error at System.out.println(....) : The field "limit" is ambiguous.
interface TestOne{
int limit=100;
void display();
}
interface TestTwo{
int limit=200;
void display();
}
public class TestInterface implements TestOne,TestTwo{
//int limit=0;
@Override
public void display() {
System.out.println("Hello... Test interface...."+limit);
}
public static void main(String [] arg){
TestInterface obj=new TestInterface();
obj.display();
}
}
-------------------------------------------
Output: Compiler error at System.out.println(....) : The field "limit" is ambiguous.
Comments
Post a Comment