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

What is meant by data hiding in java?

854


How can we find the sum of two linked lists using stack in java?

776


How do you take thread dump in java?

763


What is meant by null and void?

733


What kind of variables a class can consist of?

853


why java uses class level type casting ?

2427


What is args length in java?

929


What is the purpose of a default constructor?

829


How many bytes is a string?

831


What about instanceof operator in java?

792


What is a finally block?

759


What is java and why do we need it? Explain

803


What are different exception types exceptions available in java ?

743


What are java threads?

845


What is ternary operator? Give an example.

803