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}
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());
Join our real-time social learning platform and learn together with your friends!