A Study on Inheritance and its Type in Object Oriented Programming using JAVA
A Study on Inheritance and its Type in Object Oriented Programming using JAVA
Volume 9 Issue 1, Jan-Feb 2025 Available Online: www.ijtsrd.com e-ISSN: 2456 – 6470
INTRODUCTION
Java: Java is both a programming language and a the object-oriented paradigm (for example, in
platform. Java is a powerful, secure, and object- textbooks) lay so much emphasis on inheritance that
oriented programming language. any design without "lots of inheritance" is not good
A platform is any hardware or software environment (or certainly not "object-oriented"). At the same time,
that allows a program to run. Platform refers to Java's there is a lot of advice advocating prudence when it
comes to inheritance, such as "Favor object
runtime environment (JRE) and API.
composition over class inheritance". There have also
In Java, inheritance is a key component of OOP. It is been studies that provide inconsistent answers as to
the mechanism in Java that allows one class to inherit its benefits, while also implying that "too much"
features (fields and methods) from another. inheritance is harmful. [2]
In Java, inheritance means generating new classes Used in Java Inheritance
from existing ones. A class that inherits from another
class may reuse its methods and fields. In addition, Class: A class is a collection of objects that share
you can modify your existing class by adding common characteristics/behavior and
additional fields and methods. [1] properties/attributes. Class is not a real-world entity.
It is simply a template, blueprint, or prototype from
Since the introduction of the object-oriented which items are built.
paradigm, much has been written about the concept of
"inheritance". Some people associate the term Super Class/Parent Class: The class whose features
"object-oriented Ness" with inheritance. Inheritance are inherited is known as a superclass (or a base class
appears to be a major theme in conversations about or a parent class).
good design. Sub Class/Child Class: A subclass is a class that
All design patterns include it, frameworks rely on it, inherits from another class. In addition to the fields
and it is even used in UML. Some presentations of
@ IJTSRD | Unique Paper ID – IJTSRD75049 | Volume – 9 | Issue – 1 | Jan-Feb 2025 Page 685
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
and methods provided by the superclass, the subclass inheritance, and polymorphism are fundamental
may include its own. concepts in object-oriented modeling. The general
Reusability: Inheritance supports the concept of supporters of the object-oriented approach believe
"reusability," which means that if we want to that this model provides:
construct a new class and there is already a class that • Better abstractions (modelling information and
contains some of the code we need, we can derive our behavior together)
new class from the current class. By doing so, we
• Better maintainability (more comprehensible, less
reuse the current class's fields and functions.
fragile)
Object-Oriented Programming in Java:
• Better reusability (classes as encapsulated
Object-oriented programming (OOP) is a high-level components) [5]
computer programming language that uses objects
Review of Literature:
and associated procedures inside a programming
context to develop software programs. The object- James Gosling invented the Java programming
oriented language employs an object-oriented language in 1995. Java has gained popularity as a
programming technique that ties related data and class-based, object-oriented, and high-level
functions into an object, encouraging reuse of these programming language. It is intended to enable the
objects within the same and other systems. "write once, run anywhere" (WORA) capability,
which allows written Java code to execute without
Java is a class-based object-oriented programming
further compilation on any platform that supports
(OOP) language centered on the concept of objects.
Java. Java is well-known for its simplicity,
OOP concepts aim to increase code readability and
portability, and platform independence, making it a
reusability by specifying how to structure a Java
popular choice for creating a variety of applications
program efficiently.
such as mobile apps, web apps, desktop apps, and
Object-oriented programming combines data and games. One of Java's distinguishing advantages is its
behavior (methods) into a single location (object), platform independence, as it is compiled into
making it easier to comprehend how a program bytecode that may run on any platform that supports
operates. [3] the Java Virtual Machine. This allows developers to
Simula is recognized as the first object-oriented create code once and run it across multiple platforms
programming language. A true object-oriented without worrying about platform-specific details
programming language is one that represents [Hachadi,2023]. Furthermore, Java is widely utilized
everything as an object. Smalltalk is regarded as the in industry and academia, with numerous firms
first genuinely object-oriented programming relying on it for important business applications. [6]
language.
Object-oriented programming (OOPs) is an approach The most frequently mentioned inheritance-related
for simplifying software development and metrics are Chidamber and Kemerer's DIT and NOC
maintenance by establishing basic rules. measures [7]. A class's DIT is defined as the length of
Basic concepts of OOPs are: the longest path from the class to the root of its
inheritance hierarchy. The authors claim that the
1. Object deeper the class, the more complex it will be because
2. Class it will inherit from more ancestors, but also the
greater the opportunity for reuse. NOC for a class is
3. Inheritance defined as the number of its immediate subclasses.
4. Polymorphism The authors proposed that having more children leads
to more reuse, but it also increases the chance of
5. Abstraction erroneous abstraction. They also discovered that NOC
6. Encapsulation [4] provides an indication of the influence a class has on
the design.
The Benefits of the Object-Oriented Programming
Approach
Whether or not you develop programs in an object- Daly et al. investigated the impact of depth of
oriented manner, you must first create a model of inheritance on maintenance, as assessed by the time
what the software must be capable of and how it required to complete a maintenance activity [8]. Their
should function. Abstraction, encapsulation, findings indicated that inheritance had a detrimental
@ IJTSRD | Unique Paper ID – IJTSRD75049 | Volume – 9 | Issue – 1 | Jan-Feb 2025 Page 686
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
impact on maintenance time. This study was later
duplicated, and the results indicated the opposite
effect: inheritance increased maintenance time. The
fact that these two experiments produced such
disparate results shows that there may be more to
heredity than just "depth," yet both were modest
enough that an influence other than inheritance could
have been noticed.
Objectives:
• To Study on Inheritance and Its Type in Object
Oriented Programming Using JAVA
• To understand object-oriented principles like
abstraction, encapsulation, inheritance, Figure 1: Single Inheritance
polymorphism and apply them in solving
2. Multi-level Inheritance
problems
In Java, multi-level inheritance refers to a scenario in
• Describe the benefits of the Object-Oriented
which one class inherits properties and behaviors
programming approach
from another, which then inherits from another. This
generates a hierarchical system of classes, with each
Research Methodology: class inheriting from the one above it. [9]
@ IJTSRD | Unique Paper ID – IJTSRD75049 | Volume – 9 | Issue – 1 | Jan-Feb 2025 Page 687
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
@ IJTSRD | Unique Paper ID – IJTSRD75049 | Volume – 9 | Issue – 1 | Jan-Feb 2025 Page 688
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
a single entity known as a class. It also limits direct System.out.println("Barking...");
access to parts of an object's components, which helps
}
to prevent inadvertent interference and misuse of
methods and data. }
Java Example of Encapsulation:
public class Employee { public class TestInheritance {
private String name; public static void main(String args[]) {
private int age; Dog d = new Dog();
d.bark();
public void setName(String newName) { d.eat();
name = newName; }
} }
} class Bird {
void sing() {
return age; }
} }
}
class Sparrow extends Bird {
@ IJTSRD | Unique Paper ID – IJTSRD75049 | Volume – 9 | Issue – 1 | Jan-Feb 2025 Page 689
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
The Concept of Abstraction in Java References
Abstraction is the process of masking implementation [1] Cook, William R.; Hill, Walter; Canning, Peter
S. (1990). "Inheritance is not subtyping". POPL
details and presenting simply functionality to the user.
Abstraction in Java is performed using abstract '90: Proceedings of the 17th ACM SIGPLAN-
classes and interfaces. [12] SIGACT symposium on Principles of
programming languages. pp. 125–
Java Example of Abstraction; 135.doi:10.1145/96709.96721. ISBN 0- 89791-
abstract class Shape { 343-4.
[2] Procedure Oriented Programming (POP) vs
abstract void draw();
Object Oriented Programming (OOP). 2011.
} [3] Bertrand Meyer (2009). Touch of Class:
class Rectangle extends Shape { Learning to Program Well with Objects and
Contracts. Springer Science & Business Media.
void draw() {
p. 329.
System.out.println("drawing rectangle"); [4] Kindler, E.; Krivy, I. (2011). "Object-Oriented
} Simulation of systems with sophisticated
control". International Journal of General
}
Systems. 40 (3): 313–343.
class Circle extends Shape { [5] Bertrand Meyer (2009). Touch of Class:
void draw() { Learning to Program Well with Objects and
Contracts. Springer Science & Business Media.
System.out.println("drawing circle");
p. 329.
} [6] Hachadi, Z. Java Web Development Springboot
} Security. (LinkedIn,2023),
https://tn.linkedin.com/posts/zakaria-hachadi-
public class TestAbstraction {
176b871b0java − webdevelopment −springboot
public static void main(String args[]) { − activity − 7047332925712785408 − x4Y 0
Shape s = new Circle(); // In real scenario, [7] Chidamber, S., Darcy, D., Kemerer, C.:
object is provided through method, e.g., getShape() Managerial use of metrics for object-oriented
method software: an exploratory analysis. IEEE Trans.
Software Engineering 24(8), 629–639 (1998)
s.draw();
[8] Daly, J., Brooks, A., Miller, J., Roper, M.,
} Wood, M.: Evaluating inheritance depth on the
} maintainability of object-oriented software.
Empirical Software Engineering 1(2), 109–132
(1996)
Conclusion: [9] V. T. Lokare, P. M. Jadhav, and S. S. Patil,
Java, like any other programming language design, is ―An integrated approach for teaching object-
an experiment. Unlike most language designs, the oriented programming (C++) course, ‖ Journal
extensive adoption of Java, and the resulting of Engineering Education Transformations, vol.
widespread availability of sizable "real-world" Java 31, no. 3, pp. 17–23, 2018.
programs, allows us to ultimately evaluate that [10] R. Fojtík, ―Teaching of object-oriented
experiment in ways that most other languages simply programming, ‖ in Proc. the 12th International
cannot. Object-Oriented Programming (OOP) is Scientific Conference on Distance Learning in
critical in Java and other aspects of software Applied Informatics., 2018, pp. 273–282.
development. Embracing OOP principles such as [11] kaur, l., kaur, n., ummat, a., kaur, j., & kaur, n.
modularity, encapsulation, inheritance, (2016). research paper on object-oriented
polymorphism, and abstraction allow developers to software engineering. international journal of
design modular, maintainable, and scalable Java computer science and technology, 36-38.
applications.
[12] Lafore, Robert, Object-Oriented Programming
in C++, Fourth Edition, Sams Publishing, 2002.
ISBN 0-672- 32308-7.
@ IJTSRD | Unique Paper ID – IJTSRD75049 | Volume – 9 | Issue – 1 | Jan-Feb 2025 Page 690