Create a base class called Vehicle with name, max_speed, and tank_size attributes. Then create a derived class called Truck that inherits from the Vehicle class. The Truck should have an additional attribute called seating_capacity with default value of 5. The child class should have a method named range to calculate fuel efficiency - the calculation should be: max_speed * seating_capacity * tank_size. Override the method such that it can accept 1, 2 or 3 positional arguments.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

Create a base class called Vehicle with name, max_speed, and tank_size attributes. Then create a derived class called Truck that inherits from the Vehicle class. The Truck should have an additional attribute called seating_capacity with default value of 5. The child class should have a method named range to calculate fuel efficiency - the calculation should be: max_speed * seating_capacity * tank_size. Override the method such that it can accept 1, 2 or 3 positional arguments. 

Attached is my following code, also attached is a method for override method. Need help implementing the override method for the range to calculate the fuel effiency.

class Vehicle:
name="
max_speed
tank size
=D0
def
int
(self, name,max_speed,tank_size):
self.name = name
self.max_speed = max_speed
self.tank_size = tank_size
class Truck (Vehicle) :
seating_capacity = 5
(self, name,max_speed, tank_size,seating_capacity):
(name, max_speed, tank_size)
def
init
super ()._init
self.seating_capacity = seating_capacity
Transcribed Image Text:class Vehicle: name=" max_speed tank size =D0 def int (self, name,max_speed,tank_size): self.name = name self.max_speed = max_speed self.tank_size = tank_size class Truck (Vehicle) : seating_capacity = 5 (self, name,max_speed, tank_size,seating_capacity): (name, max_speed, tank_size) def init super ()._init self.seating_capacity = seating_capacity
#Method overriding
class Account:
def sum(self, a=None, b=None, c=None):
total = 0
if a!=None and b!=None and c!=None:
total = a+b+c
elif a!=None and b!=None:
total = a+b
else:
total = a
return total
account1 = Account()
print(account1.sum(5, 4, 1))
Transcribed Image Text:#Method overriding class Account: def sum(self, a=None, b=None, c=None): total = 0 if a!=None and b!=None and c!=None: total = a+b+c elif a!=None and b!=None: total = a+b else: total = a return total account1 = Account() print(account1.sum(5, 4, 1))
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT