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


Please Help Members By Posting Answers For Below Questions

What are the four corner stones of oop?

550


What is the use of predicate in java 8?

496


What is the purpose of the strictfp keyword?

613


What is the final keyword?

559


What is the difference between state-based unit testing and interaction-based unit testing?

497






What is the difference between jfc & wfc?

600


How to print nodes of a Binary tree?

1756


Is main a keyword in java?

542


How do you sing an Applet ?

2041


In how many ways we can create threads in java?

637


How strings are created in java?

572


How many java versions are there?

566


23. Storage space in java is of the form Stack Queue Heap List 24. What is java code embedded in a web page known as Applets Servlets scriptlets snippets 25. Which of the following attributes are compulsory with an tag?. code,height & width. 26. What does 'CODEBASE' in an applet tag specify?. Files absolute path.

2063


Can a static method be overridden in java?

559


Does constructor return any value?

585