Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
33% found this document useful (3 votes)
2K views

Problems On Overloading, Overriding and Inheritance

1. The document discusses problems involving overloading, overriding, and inheritance in Java. It provides 5 problems to solve involving creating classes that use these object-oriented programming concepts. The problems include creating classes for accounts, fruits, shapes, books in a library, and lines that inherit from other classes and override or overload methods.

Uploaded by

abcd
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
33% found this document useful (3 votes)
2K views

Problems On Overloading, Overriding and Inheritance

1. The document discusses problems involving overloading, overriding, and inheritance in Java. It provides 5 problems to solve involving creating classes that use these object-oriented programming concepts. The problems include creating classes for accounts, fruits, shapes, books in a library, and lines that inherit from other classes and override or overload methods.

Uploaded by

abcd
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Problems on Overloading, Overriding and

Inheritance

1. Create a class Account with two overloaded constructors. First


constructor is used for initializing, name of account holder, account
number and initial amount in account. Second constructor is used for
initializing name of account holder, account number, address, type of
account and current balance. Account class is having methods Deposit(),
WithDraw(), and GetBalance().Make necessary assumption for data
members and return types of the methods. Create objects of Account
class and use them.

2. Create a base class Fruit which has name ,taste and size as its attributes.
A method called eat() is created which describes the name of the fruit
and its taste. Inherit the same in 2 other class Apple and Orange and
override the eat() method to represent each fruit taste.

3. Write a program to create a class named shape. It should contain 2


methods- draw() and erase() which should print “Drawing Shape” and
“Erasing Shape” respectively.
For this class we have three sub classes- Circle, Triangle and Square and
each class override the parent class functions- draw () and erase ().
The draw() method should print “Drawing Circle”, “Drawing Triangle”,
“Drawing Square” respectively.
The erase() method should print “Erasing Circle”, “Erasing Triangle”,
“Erasing Square” respectively.
Create objects of Circle, Triangle and Square in the following way and
observe the polymorphic nature of the class by calling draw() and erase()
method using each object.
Shape c=new Circle();
Shape t=new Triangle();
Shape s=new Square();
4. Write a program to maintain data about Books in a library of a college.
Create a class Book which has following members:
private int bookNo
private String title
private String publication
private String author
private float price

Getter and setter methods for all members.


Create a class Computer derived from Book having following members
private String type (It could be Networking, DataStructure, DBMS)

Setter and getter method for type instance variable

Create a class Mathematics derived from Book having following


members
private String type (It could be Algebra, Geometry)

Setter and getter method for type instance variable

Create a class TestBook having main method. Create an object of


Computer. Scan data from user, set and print details of Computer book.
Create an object of Mathematics class. Scan data from user, set and
print details of Mathematics book.

5. Create a class Point which has following members:


private int x;
private int y;

Getter and setter methods for both instance variables

Create a class Line derived from Point having following members:


private Point point1;
private Point point2;

Getter and setter methods for both instance variables


Create a class TestLine having main method. Scan 2 point details for line
from user and print them.

You might also like