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

Java final topic

Rating
-
Sold
-
Pages
20
Uploaded on
16-11-2022
Written in
2022/2023

The document has accurate notes and easy to understand

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Course

Document information

Uploaded on
November 16, 2022
Number of pages
20
Written in
2022/2023
Type
Class notes
Professor(s)
Professor njenga
Contains
All classes

Subjects

Content preview

FINAL TOPICS IN JAVA OOPS

Five topics include

• Inheritance
• Interfaces
• Abstract class
• Principles of OOPS
• RUP process
1. INHERITANCE IN JAVA
Source of notes Inheritance in Java - Javatpoint
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 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. Inheritance represents the IS-A
relationship which is also known as a parent-child relationship.

Inheritance in Java: Why do we need it?

Code Reusability: The code written in the Superclass is common to all subclasses. Child classes
can directly use the parent class’s code.

Method Overriding: Method Overriding is achievable only through Inheritance. It is one of the
ways by which java achieves Run Time Polymorphism.

Abstraction: The concept of abstract where we do not have to provide all details is achieved
through inheritance. Abstraction only shows the functionality to the user.

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 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.

EXAMPLE: Superclass

class Bicycle {
// the Bicycle class has two fields
public int gear;
public int speed;


// the Bicycle class has one constructor
public Bicycle(int gear, int speed)
{
this.gear = gear;
this.speed = speed;
}


// the Bicycle class has three methods
public void applyBrake(int decrement)
{
speed -= decrement;
}


public void speedUp(int increment)

, {
speed += increment;
}


// toString() method to print info of Bicycle
public String toString()
{
return ("No of gears are " + gear + "\n"
+ "speed of bicycle is " + speed);
}
}



Subclass inheriting from Bicycle

class MountainBike extends Bicycle {


// the MountainBike subclass adds one more field
public int seatHeight;


// the MountainBike subclass has one constructor
public MountainBike(int gear, int speed,
int startHeight)
{
// invoking base-class(Bicycle) constructor
super(gear, speed);
seatHeight = startHeight;
}


// the MountainBike subclass adds one more method
public void setHeight(int newValue)
{
$10.49
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
shadrackndege104

Also available in package deal

Get to know the seller

Seller avatar
shadrackndege104 zetech university
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
3 year
Number of followers
0
Documents
4
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

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