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

What is Recursion Function?

751


Can a static block throw exception?

734


What is the difference between method and means?

665


Explain restrictions on using enum?

728


Differences between traditional programming language and object oriented programming language?

669






How many types of keywords are there?

649


What are exception handling keywords in java?

703


What is arraylist e in java?

604


Is node a data type in java?

603


What is array size in java?

602


Can an interface extend a class?

627


How do you compare objects in java?

591


What is function and its uses?

662


What is the use of :: in java?

667


What is use of inner class in java?

622