0% found this document useful (0 votes)
0 views6 pages

A Study on Inheritance and its Type in Object Oriented Programming using JAVA

Published in International Journal of Trend in Scientific Research and Development (ijtsrd), ISSN: 2456-6470, Volume-9 | Issue-1 , February 2025, URL: https://www.ijtsrd.com/papers/ijtsrd75049.pdf Paper Url: https://www.ijtsrd.com/engineering/computer-engineering/75049/a-study-on-inheritance-and-its-type-in-object-oriented-programming-using-java/sh-pritosh-godara

Uploaded by

Editor IJTSRD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views6 pages

A Study on Inheritance and its Type in Object Oriented Programming using JAVA

Published in International Journal of Trend in Scientific Research and Development (ijtsrd), ISSN: 2456-6470, Volume-9 | Issue-1 , February 2025, URL: https://www.ijtsrd.com/papers/ijtsrd75049.pdf Paper Url: https://www.ijtsrd.com/engineering/computer-engineering/75049/a-study-on-inheritance-and-its-type-in-object-oriented-programming-using-java/sh-pritosh-godara

Uploaded by

Editor IJTSRD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

International Journal of Trend in Scientific Research and Development (IJTSRD)

Volume 9 Issue 1, Jan-Feb 2025 Available Online: www.ijtsrd.com e-ISSN: 2456 – 6470

A Study on Inheritance and its Type in Object Oriented


Programming using JAVA
Sh. Pritosh Godara
Lecturer in Computer Engineering, Government Polytechnic, Uttawar (Palwal), Haryana, India

ABSTRACT How to cite this paper: Sh. Pritosh


This paper presents the first comprehensive empirical investigation of Godara "A Study on Inheritance and its
the widespread use of inheritance in a modern OO programming Type in Object Oriented Programming
language. We provide a set of standardized metrics for quantifying using JAVA" Published in International
Journal of Trend in
inheritance in Java programs. This article will cover the fundamentals
Scientific Research
of object-oriented programming in Java. Encapsulation, abstraction, and Development
inheritance, and polymorphism are among the core principles of this (ijtsrd), ISSN:
programming language. In this paper, we will discuss. A Study of 2456-6470,
Inheritance and Its Type in Object-Oriented Programming with Java. Volume-9 | Issue-1,
February 2025, IJTSRD75049
KEYWORDS: Inheritance, Object Oriented Programming, Java, pp.685-690, URL:
Language, Encapsulation, Abstraction, Inheritance and www.ijtsrd.com/papers/ijtsrd75049.pdf
Polymorphism, Class, Single Inheritance, Multi-Level Inheritance,
Hierarchical Inheritance, Hybrid Inheritance, Subclass Copyright © 2025 by author (s) and
International Journal of Trend in
Scientific Research and Development
Journal. This is an
Open Access article
distributed under the
terms of the Creative Commons
Attribution License (CC BY 4.0)
(http://creativecommons.org/licenses/by/4.0

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]

The study's findings are based on secondary data


gathered from credible sources such as publications,
books, magazines, and the internet. The research
design for the study is primarily descriptive. Readings
from journals These reputable articles were
discovered using search engine platforms such as
Google Scholar, global economics and business
journals, open educational materials, and other
popular websites.

Result and Discussion:


Types of Inheritance in Java
• Single Inheritance
• Multi-level Inheritance
• Hierarchical Inheritance
• Hybrid Inheritance Figure 2: Multi-level Inheritance
1. Single Inheritance 3. Hierarchical Inheritance
In Java, single inheritance refers to a subclass that In Java, hierarchical inheritance refers to how several
extends only one superclass. Here's an example that classes inherit properties and behaviors from a single
demonstrates single inheritance. parent class. This inheritance structure consists of a
single parent class and numerous child classes that
inherit from it. [10]

@ 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

Figure 3: Hierarchical Inheritance


4. Hybrid Inheritance
Hybrid inheritance in Java is a blend of multiple
inheritance and hierarchical inheritance. In hybrid
inheritance, a class is derived from two or more
classes, each of which can have its own subclasses.
Due to the diamond problem, Java does not natively
enable multiple inheritance. However, hybrid Figure 5: OOPs concepts in Java
inheritance can be produced by combining • Class
hierarchical inheritance and interface implementation.
• Object
• Encapsulation,
• Inheritance,
• Polymorphism,
• Abstraction,
Class: A class is a user-defined data type that
includes data members and member functions for
manipulating those data members. It is a group of
related types of objects. A class is a general
description of an object. It is the blueprint of an
object. Class is an extension of the structure used in
the C language. In the structure, we can merge
multiple data elements into a single entity. In the
class, we can combine various data elements and
member functions. Class is a user-defined data type
that allows us to specify both variables and functions.
Figure 4: Hybrid Inheritance Class is the most important aspect of object-oriented
programming. The class implements encapsulation,
data abstraction, and data hiding.
Object-Oriented Programming in Java:
Object: Objects are the fundamental runtime
Object-Oriented Programming (OOP) is a elements in object-oriented programming. Each
programming paradigm that employs objects and object has data and code for manipulating that data.
classes to generate models of the real world. Java, Objects can interact without needing to comprehend
being an object-oriented programming language, uses certain statistics or code. In structured programming,
these notions to give a clear modular framework for problems are tackled by separating them into
applications. [11] functions. In contrast, object-oriented programming
OOPs concepts in Java: separates the problem into objects. Thinking in terms
of objects rather than functions simplifies
programming design.
Encapsulation
Encapsulation is the process of combining data
(variables) and code (methods) that alter the data into

@ 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; }
} }

public String getName() { Polymorphism in Java


return name; Polymorphism in Java enables objects to be viewed as
instances of their parent class rather than their own
}
class. The most common application of
polymorphism in OOP is when a parent class
public void setAge(int newAge) { reference refers to a child class object.

age = newAge; Java Example of Polymorphism:

} class Bird {
void sing() {

public int getAge() { System.out.println("Bird is singing");

return age; }

} }

}
class Sparrow extends Bird {

Inheritance in Java void sing() {

In Java, inheritance is a process by which one class System.out.println("Sparrow is singing");


obtains another class's properties and behaviors }
(methods). This facilitates code reuse and method
}
overriding. A subclass inherits from a superclass.
Java Example of Inheritance:
public class TestPolymorphism {
class Animal {
public static void main(String args[]) {
void eat () {
Bird b;
System.out.println("Eating...");
b = new Sparrow(); // Polymorphism
}
b.sing();
}
}
}
class Dog extends Animal {
void bark() {

@ 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

You might also like