You are on page 1of 2

1)Create abstract class BIkeService with abstract method void getPricePerKM()

Create subclasses OLABike,UberBike and ,RapiDoBike and override the method to


show the price per km. Create BikeDemo class and in main method implement
the concept of RunTimePolymorphism by creating object of all Three classes and
by calling method.

2)Create abstract class Toy with instance variable toyName,price and instance
method, setDetails( with three parameters)to set the values and getDetails() to
print the details of the Toy. Create one abstract method void discount() to
calculate the discount.Create sub class SoftToy and override discount() with a
discount of 20% of the toy price and print the discounted price.Create another
sub class PullToy and override discount() with a discount of 25% of the toy price
and print the discounted price.

Create a class ToyDemo and in main method create the object of both the sub
classes and using Run Time Polymorphism call all the methods. You can take hard
coded values to pass in the methods.

3)Create abstract class Account with the following description:

Instance variable: acccountNumber, accountHolderName,bankName, balance;

Abstract Methods: void deposit(int amount), void withdraw(int amount)

Instance Methods: void setAccountDetails(-,-,-,-)->to set the details of account

void getAccountDetails()->to get the details of account.


Create another sub class SavingAccount with following details:

Instance method : void calculateInterest()->assuming that rate of interest is 5% for


1 year use formula p*r*t/100->here p is your balance.

Override both the abstract methods in this class. When a user will deposit some
amount, balance will get increased and when amount is withdrawn using
withdraw method balance will be decreased, also in withdraw method apply a
check that a user cannot withdraw amount more than or equal to the balance give
appropriate message to user.

Finally create a class AccountDemo and create object of SavingAccount class and
call all the methods. Take all the values from user using Scanner class.

You might also like