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

What is compile time polymorphism?

20 Answers   CTS, Elementus Technologies, Oracle,


Why is flag used in java?

0 Answers  


What are the five major types of reference sources?

0 Answers  


What is a compilation unit?

2 Answers  


What is keyword in oop?

0 Answers  






public class AboutStrings{ public static void main(String args[]){ String s1="hello"; String s2="hel"; String s3="lo"; String s4=s2+s3; //to know the hash codes of s1,s4. System.out.println(s1.hashCode()); System.out.println(s4.hashCode()); // these two s1 and s4 are having same hashcodes. if(s1==s4){ System.out.println("s1 and s4 are same."); }else System.out.println("s1 and s4 are not same."); } } Somebody told me that, == operator compares references of the objects. In the above example even though s1 and s4 are refering to same object(having same hash codes), it is printing s1 and s4 are not same. Can anybody explain in detail why it is behaving like this? Thanks in Advance RavuriVinod

4 Answers   TCS,


what is bytecode? watz the difference between machine code and bytecode?

9 Answers   Oracle,


Difference between abstract class and Interfaces?

7 Answers   CTS, iFlex, PA Consulting, Sai Softech, Value Chain,


What is overriding in java?

0 Answers  


What is difference between array and vector?

0 Answers  


Explain JMS in detail.

0 Answers   Amdocs,


What’s the difference between unit, integration and functional testing?

0 Answers  


Categories