Concepcion Holy Cross College, Inc
COLLEGE OF COMPUTER STUDIES
Case Study
in
Object Oriented
Programming
Submitted By:
ERIKA MAE CATAQUIAN
RICKY PALENCIA
RUSSEL JOHN RAMOS
BRIX KIAN YUMUL
Submitted To:
MR. SONNY LUCIANO MASANQUE
Date: November 29,2022
Table of Contents
List of Figures.............................................................................................................................. 3
A. Definition.............................................................................................................................. 4
Terms used in Inheritance....................................................................................................4
The Syntax Inheritance.........................................................................................................4
B. Case Analysis....................................................................................................................... 6
B.1 Problem......................................................................................................................... 6
B.2 Solution/Implementation................................................................................................6
B.3 Explanation.................................................................................................................... 8
C. References........................................................................................................................... 8
List of Figures
Figure 1 Sample.......................................................................................................................... 5
Figure 2. Sample Code................................................................................................................ 5
Figure 3. Sample Output..............................................................................................................6
A. Definition
Inheritance
Inheritance in Java is a mechanism in which one object acquires all the properties and
behaviors of a parent object. It is an important part of OOPs (Object Oriented
programming system) [1].
The idea behind inheritance in Java is that you can create new classes that are built upon
existing classes. When you inherit from an existing class, you can reuse methods and fields of
the parent class. Moreover, you can add new methods and fields in your current class also [1].
Inheritance represents the IS-A relationship which is also known as a parent-
child relationship [1].
Terms used in Inheritance
o Class: A class is a group of objects which have common properties. It is a template or
blueprint from which objects are created.
o Sub Class/Child Class: Subclass is a class which inherits the other class. It is also
called a derived class, extended class, or child class.
o Super Class/Parent Class: Superclass is the class from where a subclass inherits the
features. It is also called a base class or a parent class.
o Reusability: As the name specifies, reusability is a mechanism which facilitates you to
reuse the fields and methods of the existing class when you create a new class. You can
use the same fields and methods already defined in the previous class.
The Syntax Inheritance
class Subclass-name extends Superclass-name
{
//methods and fields
}
The extends keyword indicates that you are making a new class that derives from an
existing class. The meaning of "extends" is to increase the functionality.
In the terminology of Java, a class which is inherited is called a parent or superclass,
and the new class is called child or subclass.
Example:
Figure 1 Sample
As displayed in the above figure, Programmer is the subclass and Employee is the superclass.
The relationship between the two classes is Programmer IS-A Employee. It means that
Programmer is a type of Employee [2].
Figure 2. Sample Code
Figure 3. Sample Output
In the above example, Programmer object can access the field of own class as well as of
Employee class i.e. code reusability.
B. Case Analysis
B.1 Problem
Create a program with Dog class that inherits the Animal class.
B.2 Solution/Implementation
class Animal {
// field and method of the parent class
String name;
public void age() {
System.out.println("I am 2 months old.");
public void eat() {
System.out.println("I love eating and sleeping.");
// inherit from Animal
class Dog extends Animal {
// new method in subclass
public void display() {
System.out.println("My name is " + name + " :)" );
class Main {
public static void main(String[] args) {
// create an object of the subclass
Dog shipoo = new Dog();
// access field of superclass
shipoo.name = "Ely";
shipoo.display();
// call method of superclass
// using object of subclass
shipoo.age();
shipoo.eat();
}
B.3 Explanation
In our solution above, we have constructed a subclass Dog from superclass Animal. Shipoo is
an object of Dog. However, age and eat() are the attributes of the Animal class. Since Dog
inherits the field and method from Animal, we are able to access the field and method using the
object of the Dog.
C. References
[1] Javatpoint, "Inheritance," 2022.
[2] Programmiz, "Java Inheritance," 2022.