Concept explainers
// Superclass
public class Vehicle
{
private double cost;
public Vehicle (double c)
{
cost = c;
}
(Other methods …)
}
// Subclass
public class Car extends Vehicle
{
private int passengers;
public Car (int p)
{
passengers = c;
}
(Other methods …)
}
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Management Information Systems: Managing The Digital Firm (16th Edition)
Database Concepts (8th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Concepts Of Programming Languages
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Code: interface Bicycle{ //interface for bicycle void changeGear(int val); //abstract methods void changeSpeed(int inc); void applyBrakes(int dec); void ringBell(int count); } class NewCycle implements Bicycle{ //class for a new cycle int speed=0; //stores the speed value int gear=0; //stores the gear value @Override public void changeGear(int val) { //method to change the gear gear=val; } @Override public void changeSpeed(int inc) { //method to change the speed speed=speed+inc; } @Override public void applyBrakes(int dec) { //method to apply brakes speed=speed-dec; } @Override public void ringBell(int count) { //method to ring the bell for(int i=0;i<count;i++){ System.out.print("Clang!!"+" "); } System.out.println(""); } public void printState(){ //method to print the states System.out.println("Ring bell, Speed, Gear,…arrow_forwardinterface StudentsADT{void admissions();void discharge();void transfers(); }public class Course{String cname;int cno;int credits;public Course(){System.out.println("\nDEFAULT constructor called");}public Course(String c){System.out.println("\noverloaded constructor called");cname=c;}public Course(Course ch){System.out.println("\nCopy constructor called");cname=ch;}void setCourseName(String ch){cname=ch;System.out.println("\n"+cname);}void setSelectionNumber(int cno1){cno=cno1;System.out.println("\n"+cno);}void setNumberOfCredits(int cdit){credits=cdit;System.out.println("\n"+credits);}void setLink(){System.out.println("\nset link");}String getCourseName(){System.out.println("\n"+cname);}int getSelectionNumber(){System.out.println("\n"+cno);}int getNumberOfCredits(){System.out.println("\n"+credits); }void getLink(){System.out.println("\ninside get link");}} public class Students{String sname;int cno;int credits;int maxno;public Students(){System.out.println("\nDEFAULT constructor…arrow_forwardWhat is the output of the following code? Convert the abstract class into an interface and modify the codes in all classes that will maintain the same output. (Rewrite the code)arrow_forward
- class smart { public: void print() const; void set(int, int); int sum(); smart(); smart(int, int); private: int x; int y; int secret(); }; class superSmart: public smart { public: void print() const; void set(int, int, int); int manipulate(); superSmart(); superSmart(int, int, int); private: int z; }; Now answer the following questions: a. Which private members, if any, of smart are public members of superSmart? b. Which members, functions, and/or data of the class smart are directly accessible in class superSmart?arrow_forwardQuestion 13 What is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle"); } } public class Plane extends Vehicle { @Override public void drive(){ System.out.println("Flying plane"); } public static void main(String args[]) { Vehicle myVehicle= = new Plane(); myVehicle.drive(); } Driving vehicle syntax error Flying plane Driving vehicle Flying plane }arrow_forwardFinish the constructor for the KickBall class. public class Ball { public double diameter; public Ball(double diam) { diameter = diam; public class KickBall extends Ball private Color ballColor; public KickBall(double diam, Color ballColor) {arrow_forward
- class Lease{ private String name; private int aptNumber; private double rent; private int term; private static final int FEE = 10; public Lease(){ name = "XXX"; aptNumber = 0; rent = 1000; term = 12; } public void setName(String tenant) { name = tenant; } public void setAptNumber(int apt){ aptNumber = apt; } public void setRent(double monthRent) { rent = monthRent; } public void setTerm(int t){ term = t; } public String getName(){ return name; } public int getAptNumber(){ return aptNumber; } public double getRent(){ return rent; } public int getTerm(){ return term; } public void addPetFee(){ rent = rent + FEE; } } Create a class named TestLease as instructed below: Instantiate four Lease objects in the main()method. Change the aptNumber value for the first object to 20 Change the rent value…arrow_forwardUML for the following Code: public class ProductOrder { private int numBook = 0; private int numCD = 0; private int numDVD = 0; public ProductOrder(int numBook, int numCD, int numDVD){ this.numBook = numBook; this.numCD = numCD; this.numDVD = numDVD; } public int getBook(){ return numBook; } public void setBook(int numBook){ this.numBook = numBook; } public int getCD(){ return numCD; } public void setCD(int numCD){ this.numCD = numCD; } public int getDVD(){ return numDVD; } public void setDVD(int numDVD){ this.numDVD = numDVD; } public int getProductTotal(){ return getBook() + getCD() + getDVD(); } }arrow_forwardWhat is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle"); } public class Plane extends Vehicle { @Override public void drive(){ System.out.println("Flying plane"); } public static void main(String args[]) { Vehicle myVehicle myVehicle.drive(); } } = new Plane(); syntax error Driving vehicle Flying plane Flying plane O Driving vehiclearrow_forward
- 7. public class Father { public String name; public int age; // customer name Father(){ name="Hassan"; age=50;} public void display(){ System.out.println("Name:"+name); System.out.println("Age:"+age); }} Figure 3 i. Based on Figure 3, create a class named Child that inherits the Father class. Declare an instance name location (String) for class Child. ii. Define a constructor in class Child and give an appropriate initial values for the instance (name, age, location). Define a method display () in class Child, execute the display () method in superclass using the keyword super. Method display () in class Child should print the information of name, age and location. ii.arrow_forwardpublic class A { private int x; public int y; protected int z; public A() public class B extends A public class C { private int x; public int y; protected int z; public B() { x = 0; { private int x; public int y; private B z; private A w; public C() { z = new B () ; X = 0; } W = (A) z; Select correct statements assuming that defined classes belong to the same package (folder): variable x from A is accesible in C variable y from A is accesible in C variable z from A is accesible in B variable x from B is accesible in C variable y from A is accesible in B variable z from B is accesible in C variable z from A is accesible in C variable x from A is accesible in B variable y from B is accesible in Carrow_forwardClass Quiz public Quiz (int quesList, int quesMissed) {quesList = this.quesList;quesMissed = this.quesMissed;} private void calculate(){// get the point worth of each question and calculate final scorepointsPerQues = (100/quesList);scoreQuiz = quesList - quesMissed;} Class PassFailQuiz public PassFailQuiz (int quesList, int quesMissed, int scoreQuiz) { super(quesList, quesMissed);} How do I move scoreQuiz from private void calculate() to equal the third constructor value in PassFailQuiz?arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage