What is the use of an interface?

Answers were Sorted based on User's Feedback



What is the use of an interface?..

Answer / harathi

We can define a set of methods in an interface and
implement it in different ways in different classes

Is This Answer Correct ?    4 Yes 1 No

What is the use of an interface?..

Answer / muthusenthil

Interface is mearly a specification, its a design flexible
it can be used to model multiple inheritance normally java
wont supports.

Is This Answer Correct ?    3 Yes 1 No

What is the use of an interface?..

Answer / 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

More Core Java Interview Questions

What is adapter class?

12 Answers  


State some situations where exceptions may arise in java?

0 Answers  


What is an example of character?

0 Answers  


Write a java program to get a string of words and print the numbers of each word count in descending order

11 Answers   Logica CMG, Subex,


who can we create the object of a class? in how many ways we can create it (max 5)

2 Answers  






What is the best definition for data?

0 Answers  


What is command line argument in java?

0 Answers  


Define inheritance?

0 Answers  


Can we override final method?

0 Answers  


Is string an object?

0 Answers  


What is the use join() in Threads ?

5 Answers   HCL,


Can you explain the difference b/n abtract and interface with a good example,?In what cases we have use abtract and what case interface?

4 Answers   Satyam,


Categories