This is my code i have a doubt

class ab implements a,b
{

public void add()
{
System.out.println("Hi")
}
}

interface a
{
public void add();
}

interface b
{
public void add();
}

in this code i have two interface implemented in the class
has same method.just i want to know which method of
interface implemented in the class. interface a or interface
b? confused me .

Answers were Sorted based on User's Feedback



This is my code i have a doubt class ab implements a,b { public void add() { System.out.pri..

Answer / gohil

You can dynamically implement any of the interface
Ex
a intAImpObj= new ab();
b intBImpObj= new ab();

In above case intAImpObj is the implementation of a
interface and intBImpObj is the implementation of b interface

Is This Answer Correct ?    0 Yes 0 No

This is my code i have a doubt class ab implements a,b { public void add() { System.out.pri..

Answer / narayana

There should be no confusion. Since both the interfaces are
been implemented and both have the same method signature and
return type, it will
work fine and will take any of the method.
Since there is no implementation in Interfaces it is
difficult to know which interface the method is read.

Is This Answer Correct ?    0 Yes 0 No

This is my code i have a doubt class ab implements a,b { public void add() { System.out.pri..

Answer / kanu butani

There should be no confusion. Since both the interfaces are
been implemented and both have the same method, it will
work fine and will take any of the method.
Since there is no implementation in Interfaces it is
difficult to know which interface the method is read.

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More Core Java Interview Questions

List types of storage classes in java?

0 Answers   Cyient,


What is subsequence of a string?

0 Answers  


What is the purpose of the file class in java programming?

0 Answers  


Is a char always 1 byte?

0 Answers  


What is use of super keyword?

0 Answers  






There are 2 different ways to create an object. a)By using keyword "new" b)By using Class.forName ("className").newInstance(); What is the difference between these 2 methods.

3 Answers  


Can you start a thread twice in Java?

0 Answers  


What are methods?

0 Answers  


How do you compare two strings? any predefined method for this?

3 Answers  


Explain public static void main(string args[]) in java.

0 Answers  


What is the function of character?

0 Answers  


Where the CardLayout is used?

1 Answers  


Categories