What is the use of an interface?

Answer Posted / ashokmail

By using interface you can do multiple inheritance in java.

Example :
interface student{
public void add();
}

public class clloge implements student{
public clloge(){
}
public void add(){
// Some codes
}
}

public class croom implements student{
public croom(){
}
public void add(){
// Some codes
}
}

Using Interface..
public void uinter {
private student[3] stu ;

public uinter(){
stu[0] = new croom();
stu[1] = new clloge()
stu[2] = new croom();
for(int i=0;i<3;i++)
stu[i].add();
}
}

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of strings?

763


What isan abstract class and when do you use it?

1159


explain the difference between jdk and jvm?

738


Is minecraft java edition free?

814


Can we split string with in java?

729


What is the difference between path and classpath variables?

700


How can we avoid including a header more than once?

778


What is fail fast in java?

760


What is identifier with example?

778


What is return used for in java?

710


Java Compiler is stored in JDK, JRE or JVM?

1215


Can each java object keep track of all the threads that want to exclusively access it?

732


How is hashcode calculated in java?

690


What is the syntax and characteristics of a lambda expression?

778


What is difference between pointer and reference?

700