Garantie de satisfaction à 100% Disponible immédiatement après paiement En ligne et en PDF Tu n'es attaché à rien 4,6 TrustPilot
logo-home
Autre

Complete Java Notes for Beginners & BCA/College Students

Note
-
Vendu
-
Pages
52
Publié le
28-08-2025
Écrit en
2025/2026

These notes cover Java Unit – 2 in detail with clear explanations and programs. Topics include control statements (if, switch, loops), arrays, strings (String, StringBuffer, StringBuilder), constructors (default, parameterized, overloading), and static keyword. Written in simple English with examples, these notes are perfect for BCA students and for exam preparation in Java programming.

Montrer plus Lire moins
Établissement
Cours

Aperçu du contenu

Java Unit-3


Inheritance in Java
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).

The idea behind inheritance in Java is that we can create new classes that are built upon
existing classes. When we inherit methods from an existing class, we can reuse methods
and fields of the parent class. However, we can add new methods and fields in your current
class also.


What is Inheritance?
Inheritance in Java enables a class to inherit properties and actions from another class,
called a superclass or parent class. A class derived from a superclass is called a subclass
or child group. Through inheritance, a subclass can access members of its superclass
(fields and methods), enforce reuse rules, and encourage hierarchy.

Inheritance represents the IS-A relationship which is also known as a parent-child
relationship.


Why use inheritance?
○​ For Method Overriding (so runtime polymorphism can be achieved).
○​ For Code Reusability.


Terms used in Inheritance
○​ Class: A class is a group of objects which have common properties. It is a
template or blueprint from which objects are created.
○​ 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.
○​ 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.
○​ 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 of Java Inheritance
​ class Subclass-name extends Superclass-name
​ {
​ //methods and fields
​ }
The extends keyword indicates that we 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 that is inherited is called a parent or superclass, and the
new class is called child or subclass.

Java Inheritance Example




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.

Example
​ class Employee{
​ float salary=40000;
​ }
​ class Programmer extends Employee{
​ int bonus=10000;
​ }

, ​ public class Main{
​ public static void main(String args[]){
​ Programmer p=new Programmer();
​ System.out.println("Programmer salary is:"+p.salary);
​ System.out.println("Bonus of Programmer is:"+p.bonus);
​ }
​ }
Output:

Programmer salary is:40000.0
Bonus of programmer is:10000

In the above example, Programmer object can access the field of own class as well as of
Employee class i.e. code reusability.


Types of Inheritance in Java
On the basis of class, there can be three types of inheritance in java: single, multilevel and
hierarchical.

In Java programming, multiple and hybrid inheritance is supported through interface only.
We will learn about interfaces later.

To read more: Interface in Java



Note: Multiple inheritance is not supported in Java through class.




Single Inheritance
When a class inherits another class, it is known as a single inheritance. In the example
given below, Dog class inherits the Animal class, so there is the single inheritance.

To read more: Single Inheritance in Java

, Example
​ class Animal{
​ void eat(){System.out.println("eating...");}
​ }
​ class Dog extends Animal{
​ void bark(){System.out.println("barking...");}
​ }
​ public class Main{
​ public static void main(String args[]){
​ Dog d=new Dog();
​ d.bark();
​ d.eat();
​ }}
Output:

barking...
eating...



Multilevel Inheritance
When there is a chain of inheritance, it is known as multilevel inheritance. As you can see in
the example given below, BabyDog class inherits the Dog class which again inherits the
Animal class, so there is a multilevel inheritance.

To read more: Multilevel Inheritance in Java

École, étude et sujet

Cours

Infos sur le Document

Publié le
28 août 2025
Nombre de pages
52
Écrit en
2025/2026
Type
AUTRE
Personne
Inconnu

Sujets

€9,87
Accéder à l'intégralité du document:

Garantie de satisfaction à 100%
Disponible immédiatement après paiement
En ligne et en PDF
Tu n'es attaché à rien

Faites connaissance avec le vendeur
Seller avatar
lavinajangid1

Document également disponible en groupe

Faites connaissance avec le vendeur

Seller avatar
lavinajangid1 MCIT
S'abonner Vous devez être connecté afin de suivre les étudiants ou les cours
Vendu
-
Membre depuis
6 mois
Nombre de followers
0
Documents
4
Dernière vente
-

0,0

0 revues

5
0
4
0
3
0
2
0
1
0

Documents populaires

Récemment consulté par vous

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions