Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (dawnr):

If i have couple of methods who share the same attributes (which are private) and i want to put them in different classes(methods)..how do i call the methods? {in java}

OpenStudy (mathmate):

So you'd like to create different methods (with different names, but) with the same attributes (arguments, or parameters)? The question is a little vague, but I try to answer it with some examples. If the examples don't address your question, just post. If you put them in different classes but called static, then you can call them without creating any instances, ex. Math.random(), Math.sin(x), etc. If they are not static methods, then they have to be called via an instance, ex. class Cars{ public Cars(){...} private double price(){ return...;} } Then in the calling class, you would put ... Cars jeep=new Cars(...); System.out.println("Price of a jeep="+jeep.price()); ... and perhaps similarly, you would have Trucks volvo=new Trucks(...), System.out.println(.....volvo.price());

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Jalissa21: What does adenoma mea?
32 minutes ago 2 Replies 0 Medals
Twilightt: How Can We Prevent Gun Violence in American Schools?
31 minutes ago 4 Replies 1 Medal
Twaylor: possible?
2 days ago 5 Replies 0 Medals
Arriyanalol: hekp
4 days ago 33 Replies 0 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!