Help me Abstraction please | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help me Abstraction please

How create on abstract auto class with field for the car name and price. Then include get and set methods these feilds. And tha setprice() method is abstract. Ans create two subclasses for individual automobile makers(for example,Ford and Jeep) and include oppropriate setprice() metods in each subclass.

6th Feb 2017, 10:23 PM
shamal salam abdulrahman
shamal salam abdulrahman - avatar
2 Answers
+ 1
abstract public class Car { protected double price ; protected String name ; abstract public void setPrice ( double price ) ; public double getPrice ( ) { return this.price ; } public String getName ( ) { return this.name ; } public void setName ( String name ) { this.name = name ; } } public class Ford extends Car { public void setPrice ( double price ) { this.price = price * 1.2 ; } } public class Jeep extends Car { public void setPrice ( double price ) { this.price = price * 0.8 ; } }
7th Feb 2017, 12:10 AM
K.C. Leung
K.C. Leung - avatar
+ 1
Thank you very much
7th Feb 2017, 12:12 AM
shamal salam abdulrahman
shamal salam abdulrahman - avatar