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
Can you add null to a list java?
What is difference between add() and addelement() in vector?
How is java hashmap implemented?
Can we have any other return type than void for main method?
Can we execute java program without main method?
Can a main method be declared final?
What is an exception in java?
What are the drawbacks for singleton class?
What is substring in java?
What is meant by 'bit masking' in java?
Explain the difference between serializable and externalizable in java?
What are different type of exceptions in java?
What does three dots mean in java?
What is java autoboxing?
What is the preferred size of a component in java programming?