"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
why are there separate wait and sleep methods? : Java thread
Explain JMS in detail.
What are the different types of constructor?
Define interface in java?
What are different types of arrays?
Which of the following is not an isolation level in the JDBC
how to write a program for sending mails between client and server
Can we call virtual funciton in a constructor ?
What is collection class in java? List down its methods and interfaces.
Which programming language is most secure?
what is mena by object block any what is the use of that
Can main() method in java can return any data?
What is final variable?
What is a dynamic array in java?
What is the purpose of file class?