Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



Package1 and Package2 both have a method name lets say "methodA" with different implement..

Answer / manoj

// Do you want to say like this?

//import like this:

import Package1.classA
import Package2.classB

//use it in your class
class yourclass
{
classA.methodA(); // Package1 method call
classB.methodA(); // Package2 method call
}

Is This Answer Correct ?    27 Yes 3 No

Package1 and Package2 both have a method name lets say "methodA" with different implement..

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

Package1 and Package2 both have a method name lets say "methodA" with different implement..

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

Package1 and Package2 both have a method name lets say "methodA" with different implement..

Answer / chirag

Is it really so difficult? Use fully qualified names. :D

Is This Answer Correct ?    5 Yes 0 No

Package1 and Package2 both have a method name lets say "methodA" with different implement..

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

Package1 and Package2 both have a method name lets say "methodA" with different implement..

Answer / swwety

it will give compilation error

Is This Answer Correct ?    0 Yes 6 No

Package1 and Package2 both have a method name lets say "methodA" with different implement..

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

Post New Answer

More Core Java Interview Questions

Is it possible to write method inside method

4 Answers   L&T,


What is the purpose of sizeof operator?

0 Answers  


How to transfer data from an Applet to Servlet ?

1 Answers  


What is hashmap and map?

0 Answers  


How to handle a web browser resize operation?

0 Answers  


What is jrmp?

0 Answers  


Is java an open source?

0 Answers  


What is the ==?

0 Answers  


What does this() represent, and how is it used in Java?

2 Answers  


List two java ide’s?

0 Answers  


Is nullpointerexception checked or unchecked?

0 Answers  


what do you understand by the term string with respect to java?

0 Answers  


Categories