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?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / sriragv
You can not call a method like above unless untill ur
classes are static.
You can create instance and u can use as
Instance.method();
| Is This Answer Correct ? | 17 Yes | 1 No |
Answer / chirag
Is it really so difficult? Use fully qualified names. :D
| Is This Answer Correct ? | 5 Yes | 0 No |
Answer / 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 |
Answer / shiv
//import like this:
import Package1.class
import Package2.class
//use it in your class
class yourclass
{
class.methodA(); // Package1 method call
class.methodA(); // Package2 method call
}
| Is This Answer Correct ? | 6 Yes | 19 No |
What is treeset and treemap in java?
What is the difference between ArrayList and Vector? which one is better in Java
0 Answers SkillGun Technologies,
When you say String is immutable, what do you mean by that? Say I have String s = "Ness" s= s+"Technologies"; What will happen? If the value gets appended, then what is the meaning of immutable here?
What are untrusted applets?
How many bits is a string?
what is the difference between sleep() and Wait()?
What are the different types of data structures in java?
Difference between String & StringBuffer
16 Answers IBM, Infosys, Tech Mahindra, Wipro,
there are N number of matchboxes numbered 1...N.each matchbox contain various number of stick.Two player can alternatevely pick some amount of stick from the higest stick containing box . The player is condidered win if there is no stick after his move.Find the final move so that the move player win. Note:In case the number of stick is equal ,pick the stick from the higest numbered box.
How to compare two strings in java program?
What is the point of polymorphism java?
What is static variable with example?