Professional Documents
Culture Documents
Q2 Lesson 1 OOP
Q2 Lesson 1 OOP
Class
OBJECT Abstraction
ORIENTED Encapsulation
CONCEPTS
Inheritance
Polymorphism
Object Oriented programming is a programming style which is associated with the concepts like
class, object, Inheritance, Encapsulation, Abstraction, Polymorphism. It focuses on implementing real
world objects using Classes to create variation of object, that has attribute and purpose
OBJECT
Object means a real-world entity such as human, animals, pen, chair, table, etc.
-Properties
-Task performed
-Instance of a class
Example: Person
Name Walk
Age Read
Address Write
Sex Run
CLASS - is a definition of objects of the same kind. In other words, a class is a blueprint, template, or
prototype that defines and describes the static attributes and dynamic behaviors common to all objects
of the same kind.
A Class is a 3-
Compartment Box
Encapsulating Data
and Operations
//Attribute
//methods or purpose
}
Program:
Example:
Public Person class {
Person //ATTRIBUTES
- FirstName
- Last Name
String firstName;
- Sex
String lastName;
- Age
Char sex;
Int age;
}
SHOW DEMO
Class Instantiation – the process of creating an object using a class
so we can use it on our program
Syntax:
ClassName identifiers = new ClassName();
Example:
Person p = new Person();
SHOW DEMO
ACCESSING Attributes
Syntax:
Sample Program
WRITING Attributes
identifier.attribute = value; p.firstName = “Juan”;
p.lastName = “Cruz”;
p.Sex = ‘M’;
p.Age = 19’
READING Attributes
System.out.println(identifier.attribute);
System.out.println(p.firstName);
CONSTRUCTOR
CREATING Constructor
USING CONSTRUCTOR
SYNTAX: EXAMPLE:
className(){ Product(){
//constructor System.out.println(“Product created”);
} }
} }
Creating Constructor
Constructors are used to initialize attributes
EXAMPLE:
String name;
float price;
SHOW DEMO
The this keyword refers to the
class itself.
THIS keyword
The this keyword will enable
you to access global variables
inside the class if you have the
same variable names in a
parameter.
•ClassName identifiers = New
ClassName(parameters);
Constructors
USER INPUT Object Creation