0% found this document useful (0 votes)
6 views15 pages

Slot 2 Review

The document provides an overview of key Object-Oriented Programming (OOP) concepts including abstraction, encapsulation, inheritance, and polymorphism, along with their definitions and examples. It discusses the use of abstract classes and interfaces, the importance of encapsulation in hiding data, and the structure of collections such as lists, sets, and maps. Each concept is illustrated with examples to demonstrate their application in programming.

Uploaded by

kanyken1210
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)
6 views15 pages

Slot 2 Review

The document provides an overview of key Object-Oriented Programming (OOP) concepts including abstraction, encapsulation, inheritance, and polymorphism, along with their definitions and examples. It discusses the use of abstract classes and interfaces, the importance of encapsulation in hiding data, and the structure of collections such as lists, sets, and maps. Each concept is illustrated with examples to demonstrate their application in programming.

Uploaded by

kanyken1210
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/ 15

SLOT 2 REVIEW

CONTENT

• Class & Class Components


• Variables & Methods
• OOP Concepts: Abstraction, Encapsulation, Inheritance, Polymorphism
• Collections
• Regular expressions
• Exception handling
• Basic I/O

2
ABSTRACTION

• Abstraction is one of the main ways that we deal with complexity. It is the idea of
simplifying a concept in the problem domain.
• Abstraction breaks a concept down into a simplified description that emphasizes
the essentials needed for the concept, within some context.

DeliveryDriver
You were asked to create a DeliveryDriver class.
deliveryArea: DeliveryArea
You thought about the problem, and reduced it to
eyeColor: Color
its most essential aspects… things like takeOrder, height: int
DeliveryArea, etc. Irrelevant things in the context
(e.g., driver's height or eye colour) are ignored. takeOrder()

3
ABSTRACTION

• Abstract Classes and Interfaces:


o Abstraction is often achieved through abstract classes and interfaces in Java. Abstract
classes can have abstract (unimplemented) methods, and interfaces can declare
method signatures without providing implementations.
• Defining Common Characteristics:
o Abstract classes and interfaces define common characteristics and behaviors that
subclasses or implementing classes must adhere to. This promotes code reuse and
standardization.

4
abstract CLASS

• The abstract class is declared with the abstract modifier.


• Here we are declaring an abstract class called Animal.

• An abstract class is a class that's incomplete.


• We cannot create an instance of an abstract class.

• An abstract class can still have a constructor, which will be called by its subclasses,
during their construction.
5
abstract CLASS

• The purpose of an abstract class is to define the behavior its subclasses are
required to have, so it always participates in inheritance.

• A class that extends an abstract class, can also be abstract itself.

• An abstract class can extend a concrete class.

6
abstract METHOD

• Abstract methods can only be declared on an abstract class or interface.


• There is no concrete method for a subclass to inherit code from.
o the subclass must provide a concrete method for any abstract method declared on
its parent.
• The subclass won't compile if it doesn't implement the abstract methods.

7
ENCAPSULATION

• Encapsulation in OOP usually has two meanings.


• One is the bundling of behavior and attributes on a single object.
• The other is the practice of hiding fields, and some methods, from public access.

Access keyword Description

public public means any other class in any package can access this class.
protected allows classes in the same package, and any subclasses
protected
in other packages, to have access to the member.
When the modifier is omitted, this has special meaning, called
package access, meaning the member is accessible only to
classes in the same package
private private means that no other class can access this member
8
INHERITANCE

Animal

Vertebrates

Warm-blooded Cold-blooded

Mammal Bird Fish Reptiles

Dog Goldfish

Cat Salmon
9
INHERITANCE
Animal
type: String
• Dog inherits from Animal. size: String
• Dog "is-a" type of Animal. weight: double
move(String speed)
• When a Dog object is created, it will inherit makeNoise()
Animal's attributes (type, size and weight) &
Animal's methods.
• Dog class’ specific fields and behavior can
Dog
also be specialised
earShape: String
• Keywords: extends, super() tailShape: String
• Method overriding bark()
run()
walk()
wagTail() 10
POLYMORPHISM

• Polymorphism = many forms. Movie


title: String

watchMovie()
• Method’s behavior that occurs, while the
program is executing, depends on the
runtime type of the object.

Adventure Comedy Comedy

Movie & its subclasses


Sample code
Main.java
11
COLLECTIONS

12
COLLECTIONS

13
COLLECTIONS: a Big Picture

14
COLLECTIONS: some common classes

• A List is An ordered collection (also known as a sequence).


o These can be sequenced in memory like an ArrayList, or maintain links to the next
and previous values, as a LinkedList.
• A Set is a collection conceptually based off of a mathematical set.
o Importantly, it contains no duplicate elements, and isn't naturally sequenced or
ordered.
• A Map is a collection that stores key and value pairs.
o Keys need to be unique, but values don't.

15

You might also like