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
What is the difference between state-based unit testing and interaction-based unit testing?
Are arrays immutable in java?
Can we define private and protected modifiers for variables in interfaces?
What do you know about java?
Why is java multithreaded?
When is update method called?
What is predicate in java?
what is the constructor and how many types of constructors are used in java?
What is the difference between heap memory and stack memory?
What is the difference between the ">>" and " >>>" operators in java?
What is difference between static variable and global variable?
What is array pointers ?
What is the purpose of the strictfp keyword?
What is meant by interface?
What is string in java is it a data type?