"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
What is xslt in java?
what are Hostile Applets?
How to perform linear search in java?
How many types of design patterns are there?
When super keyword is used?
Does anyone still use java?
How hashset works internally in java?
Which class represents the socket that both the client and server use to communicate with each other?
Can singleton class be inherited in java?
How can a gui component handle its own events?
How do you use equal in java?
How would you convert bytes to string?
How does sublist works in java?
What is difference between fileinputstream and filereader in java?
How to create a base64 decoder in java8?