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 are the differences between checked exception and unchecked exception?

526


Describe string intern() methodology

592


How does arraylist size increase in java?

529


What is a JAR file?

590


How many types of array are there?

546






Can we have two main methods in a java class?

534


How is it possible in java programming for two string objects with identical values not to be equal under the == operator?

560


What does sizeof return?

553


What is thread safe singleton?

511


Can an interface have a constructor?

511


What is string made of?

525


What is variable in java?

520


What is balanced tree in java?

532


What is public/private protected in java?

541


Is oracle charging for java?

546