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 / munesh yadav

Frist make instances of the two classes and then call the
respective methods.

eg. Package1 has a classA with fun functionA(Arg1,Arg2)
and Package2 has a ClassB with fun functionA(Arg1,Arg2)
import package1.classA;
import package2.classB;
public Class main{
public void main(String a[]){
classA obj1=new classA();
obj1.functionA(arg1,arg2);
classB obj2=new classB();
obj2.functionA(arg1,arg2);
}
}

Is This Answer Correct ?    19 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does string is thread-safe in java?

595


Are arrays immutable in java?

550


What are predefined functions?

582


What is an infinite loop?

550


What is a function argument in java?

522






How define set in java?

518


How will you load a specific locale?

540


Give a brief description of java socket programming?

532


Can we override the static method?

580


What do the thread?class methods run() and start() do?

547


How does singleton class work?

533


What is finally and finalize in java?

602


Why to use nested classes in java? (Or) what is the purpose of nested class in java?

530


How can a gui component handle its own events?

599


What is super?

589