"we cannot create an object of interface but we can create
a variable of it".diacuss the statement with the help of
an example.
Answer Posted / guest
1. Suppose interface interfaceDemo.java is as below
interface interfaceDemo {
public void methodA();
public void methodB();
}
2. Suppose class InterfaceDemoMain.java is as below
class InterfaceDemoMain implements interfaceDemo {
public void methodA() {
System.out.println("Inside methodA");
}
public void methodB() {
System.out.println("Inside methodB");
}
public void methodC() {
System.out.println("Inside methodC");
}
public static void main(String[] ar) {
InterfaceDemoMain idm = new InterfaceDemoMain();
interfaceDemo id;
id = idm;
id.methodA();
id.methodB();
id.methodC();// error
idm.methodC();
}
}
3. Here id.methodC(); will give error, only methods declared
inside interface are accessible to interface reference.
| Is This Answer Correct ? | 13 Yes | 0 No |
Post New Answer View All Answers
explain the difference between jdk and jvm?
Describe the process as to how substring() methodology mechanisms in java.
What are three advantages of using functions?
What purpose do the keywords final, finally, and finalize fulfill?
Why is core java important?
Can we use String with switch case?
What is the default value of an object reference declared as an instance variable?
In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?
What is considered an anti pattern?
Is arraylist dynamic in java?
How many types of array are there?
What are advantages of exception handling in java?
What is a programming object?
take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).
Explain the difference between private, public, package and protected in java?