Package1 and Package2 both have a method name lets say
"methodA" with different implementation. When I import both
the packages in a java class how can I use both the methods?

Answer Posted / mohan

Since all non static methods in JAVA supports polymorphism,
we can call the respective methods using its instances..
considering that methodA is non static method we can call it
using instance of the respective class.. so Create instances
of the respective classes and then call the methods ..


for eg:

ClassA ins1=new ClassA();
ClassB ins2=new ClassB();

ins1.methodA();
ins2.methodA();

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you add null to a list java?

803


What is difference between add() and addelement() in vector?

1316


How is java hashmap implemented?

786


Can we have any other return type than void for main method?

763


Can we execute java program without main method?

749


Can a main method be declared final?

825


What is an exception in java?

896


What are the drawbacks for singleton class?

769


What is substring in java?

844


What is meant by 'bit masking' in java?

888


Explain the difference between serializable and externalizable in java?

765


What are different type of exceptions in java?

754


What does three dots mean in java?

885


What is java autoboxing?

737


What is the preferred size of a component in java programming?

762