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
How do you insert a line break?
Is final static java?
How to implement a multithreaded applet?
Why is the singleton pattern considered to be an anti pattern?
What is string pool?
Can a class be declared as static?
What is meant by polymorphism?
What are the legal parameters?
Is void a keyword in java?
Why main() method is public, static and void in java ?
What do you mean by an interface in java?
What are streams?
what is the difference between preemptive scheduling and time slicing? : Java thread
What is the final method?
What are the types of exceptions?