100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Other

Complete Java Notes for Beginners & BCA/College Students

Rating
-
Sold
-
Pages
52
Uploaded on
28-08-2025
Written in
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.

Show more Read less
Institution
Course

Content preview

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

Written for

Course

Document information

Uploaded on
August 28, 2025
Number of pages
52
Written in
2025/2026
Type
OTHER
Person
Unknown

Subjects

$10.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
lavinajangid1

Also available in package deal

Get to know the seller

Seller avatar
lavinajangid1 MCIT
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
6 months
Number of followers
0
Documents
4
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions