Answer to Question #318557 in Java | JSP | JSF for oslo

Question #318557

Question 1: (Inheritance)

Consider a scenario where you have been given three classes, namely Vehicle, Bus, and

School_Bus. The School_Bus class is supposed to inherit all characteristics of both the Vehicle

and the Bus class. Explain and illustrate how you are going to achieve this considering you are using Java programming language.



1
Expert's answer
2022-03-26T06:42:52-0400
class Vehicle{
    public void Run(){
        System.out.println("I'm driving");
    }
}

class Bus extends Vehicle{
    public void Run(){
        System.out.println("I'm driving home");
    }
}

class School_Bus extends Vehicle{
    public void Run(){
        System.out.println("I'm going to school");
    }
}



public class Main {
    public static void main(String[] args) {

        Vehicle ver = new Vehicle();
        Vehicle bus = new Bus();
        Vehicle schoolBus = new School_Bus();

        ver.Run();
        bus.Run();
        schoolBus.Run();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS