SlideShare a Scribd company logo
04. Review OOP with Java
Oum Saokosal
Master of Engineering in Information Systems, South Korea
855-12-252-752
oum_saokosal@yahoo.com
Agenda
• Array
• Class/Object
• Inheritance
• Abstract Class
• Overridden Methods
• Interface
• Polymorphism
Array
• int[] a = new int[10];
a[0]=10;
a[1]=20;
a[9]=45;
• double[] d = new double[5][10];
d[0][0]=9.9;
d[0][1]=3.14;
a[4][9]=9.8;
Class/Object
public class Aclass {
public Aclass(){//it’s called constructor
Bclass b = new Bclass(); //b is object/instance
b.hello(); //b invokes hello() method
}
public static void main(String[] args){
new Aclass();
}
}
class Bclass {
public void hello(){ //hello() is a method
System.out.print("Hello Everyone");
}
}
Inheritance
in UML Diagram
Child1
Parent
Child2 Child3
Inheritance
public class Child extends Parent{
public Child(){
System.out.println(money);
System.out.println(gold);
System.out.println(rich());
System.out.println(job());
}
public static void main(String[] args){
new Child();
}
}
class Parent{
public double money = 500000;
public double gold = 200;
public boolean rich(){
return true;
}
public String job(){
return "Doctor";
}
}
Abstract class
in UML Diagram
Duck
<<abstract>>
Bird
Swallow
Abstract Class
public abstract class Bird {
public String color;
public abstract boolean isFlyable();
public void sound(){
System.out.println("Default”);
}
}
class Duck extends Bird{
public boolean isFlyable() {
return false;
}
public void sound(){
System.out.println("Quack ");
}
}
class Swallow extends Bird{
public boolean isFlyable() {
return true;
}
}
Overridden Method
Interface
public interface Flyable {
public String fly();
}
class Chicken implements Flyable{
@Override
public String fly() {
return "Low and near";
}
}
class Swallow implements Flyable{
@Override
public String fly() {
return "High and far";
}
}Chicken
<<interface>>
Flyable
Swallow
Abstract class vs Interface (Same)
Abstract class
• All subclasses of the
abstract class have to
override all abstract
methods.
• You cannot use new
operator to create an
instance from an abstract
class.
Bird b = new Bird();
• Abstract class can be used
as a type.
Bird b;
Interface
• All classes implemented the
interface have to override
all methods.
• You cannot use new
operator to create an
instance from an interface.
Flyable fly = new Flyable();
• Interface can be used as a
type.
Flyable fly;
Abstract class vs Interface (Different)
Abstract class
• To declare an abstract class,
use abstract keyword.
public abstract class B{
}
• A class can extend only one
abstract class.
class A extends B{
}
• In relationship, we say
A is B.
Interface
• To declare an interface, use
abstract keyword.
public interface B{
}
• A class can implement more
than one interface.
class A implements C, D, E{
}
• In relationship, we
A has C, D, and E.
Polymorphism
What is polymorphism?
• Polymorphism is a mechanism to allow a
single variable to refer to objects from
different classes.
Polymorphism
public class MyPoly {
public static void main(String[] args) {
Bird b; // b is Bird
b = new Duck(); // b refers to Duck
b.sound(); // b invokes Duck’s sound
b = new Chick(); // b refers to Chick
b.sound(); //b invokes Chick’s sound
}
}
abstract class Bird{
public abstract void sound();
}
class Duck extends Bird{
public void sound(){
System.out.println("Quack");
}
}
class Chick extends Bird{
public void sound(){
System.out.println("Cheep");
}
}
Go on the next slide

More Related Content

PPT
Objected-Oriented Programming with Java
PPT
Java Programming - Polymorphism
PDF
Java OOP Programming language (Part 5) - Inheritance
PPT
Java oops PPT
PDF
Java OOP Programming language (Part 3) - Class and Object
PDF
Java OO Revisited
PDF
Object oriented programming With C#
PDF
Core java complete notes - Contact at +91-814-614-5674
Objected-Oriented Programming with Java
Java Programming - Polymorphism
Java OOP Programming language (Part 5) - Inheritance
Java oops PPT
Java OOP Programming language (Part 3) - Class and Object
Java OO Revisited
Object oriented programming With C#
Core java complete notes - Contact at +91-814-614-5674

What's hot (20)

PDF
PPT
Java Programming - Introduction to Abstract Class
PPSX
Inner Classes
PPT
Java Programming - Inheritance
PPTX
Classes in c++ (OOP Presentation)
PPTX
Classes, objects in JAVA
PDF
ITFT-Classes and object in java
PPTX
Multiple inheritance possible in Java
PPTX
Object Oriented Programming with C#
PPT
Java basic
PPTX
Object Oriented Programming_Lecture 2
PPT
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
PPTX
Introduction to OOP(in java) BY Govind Singh
PPTX
‫‫Chapter4 Polymorphism
PDF
Object-oriented Programming-with C#
PPT
Oops Concept Java
PPT
Oops in Java
PPTX
Introduce oop in python
PPTX
oops concept in java | object oriented programming in java
Java Programming - Introduction to Abstract Class
Inner Classes
Java Programming - Inheritance
Classes in c++ (OOP Presentation)
Classes, objects in JAVA
ITFT-Classes and object in java
Multiple inheritance possible in Java
Object Oriented Programming with C#
Java basic
Object Oriented Programming_Lecture 2
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
Introduction to OOP(in java) BY Govind Singh
‫‫Chapter4 Polymorphism
Object-oriented Programming-with C#
Oops Concept Java
Oops in Java
Introduce oop in python
oops concept in java | object oriented programming in java
Ad

Viewers also liked (17)

PPTX
Object Oriended Programming with Java
PPTX
10.1. Android Audio
PPTX
07.4. Android Basic Simple Browser (WebView)
PPTX
10.3 Android Video
PPTX
06. Android Basic Widget and Container
PPTX
11.1 Android with HTML
PPTX
07.3. Android Alert message, List, Dropdown, and Auto Complete
PPTX
08.1. Android How to Use Intent (explicit)
DOCX
Using intents in android
PPTX
07.1. Android Even Handling
PPTX
10.2 Android Audio with SD Card
PPTX
12. Android Basic Google Map
PPTX
Database Concept - ERD Mapping to MS Access
PPTX
09.1. Android - Local Database (Sqlite)
PPTX
Database Concept - Normalization (1NF, 2NF, 3NF)
PPT
Java Programming - Abstract Class and Interface
PPT
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Object Oriended Programming with Java
10.1. Android Audio
07.4. Android Basic Simple Browser (WebView)
10.3 Android Video
06. Android Basic Widget and Container
11.1 Android with HTML
07.3. Android Alert message, List, Dropdown, and Auto Complete
08.1. Android How to Use Intent (explicit)
Using intents in android
07.1. Android Even Handling
10.2 Android Audio with SD Card
12. Android Basic Google Map
Database Concept - ERD Mapping to MS Access
09.1. Android - Local Database (Sqlite)
Database Concept - Normalization (1NF, 2NF, 3NF)
Java Programming - Abstract Class and Interface
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Ad

Similar to 04. Review OOP with Java (20)

PPTX
Inheritance.pptx
PPTX
Lecture-10_PHP-OOP.pptx
PPTX
Abstraction
PDF
OOPs Concepts - Android Programming
PPTX
Design pattern
PPT
Visula C# Programming Lecture 8
PPT
02-OOP with Java.ppt
PPT
025466482929 -OOP with Java Development Kit.ppt
PPT
06 InheritanceAndPolymorphism.ppt
PPT
InheritanceAndPolymorphismprein Java.ppt
PPTX
inheritance, Packages and Interfaces.pptx
PPTX
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
PPTX
Polymorphism in C# Function overloading in C#
PPTX
OOPS_Unit2.inheritance and interface objected oriented programming
PPT
Inheritance
PPTX
L04 Software Design 2
PPTX
Inheritance & interface ppt Inheritance
PPTX
2CPP14 - Abstraction
PPTX
Class introduction in java
PPT
java tutorial 3
Inheritance.pptx
Lecture-10_PHP-OOP.pptx
Abstraction
OOPs Concepts - Android Programming
Design pattern
Visula C# Programming Lecture 8
02-OOP with Java.ppt
025466482929 -OOP with Java Development Kit.ppt
06 InheritanceAndPolymorphism.ppt
InheritanceAndPolymorphismprein Java.ppt
inheritance, Packages and Interfaces.pptx
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
Polymorphism in C# Function overloading in C#
OOPS_Unit2.inheritance and interface objected oriented programming
Inheritance
L04 Software Design 2
Inheritance & interface ppt Inheritance
2CPP14 - Abstraction
Class introduction in java
java tutorial 3

Recently uploaded (20)

PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
PDF
Landforms and landscapes data surprise preview
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
High Ground Student Revision Booklet Preview
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
Types of Literary Text: Poetry and Prose
PPTX
How to Manage Global Discount in Odoo 18 POS
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
PPTX
Congenital Hypothyroidism pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PDF
Sunset Boulevard Student Revision Booklet
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
How to Manage Bill Control Policy in Odoo 18
PDF
English Language Teaching from Post-.pdf
Cardiovascular Pharmacology for pharmacy students.pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Landforms and landscapes data surprise preview
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
High Ground Student Revision Booklet Preview
Revamp in MTO Odoo 18 Inventory - Odoo Slides
Types of Literary Text: Poetry and Prose
How to Manage Global Discount in Odoo 18 POS
Skill Development Program For Physiotherapy Students by SRY.pptx
Congenital Hypothyroidism pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
Sunset Boulevard Student Revision Booklet
Week 4 Term 3 Study Techniques revisited.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
How to Manage Bill Control Policy in Odoo 18
English Language Teaching from Post-.pdf

04. Review OOP with Java

  • 1. 04. Review OOP with Java Oum Saokosal Master of Engineering in Information Systems, South Korea 855-12-252-752 [email protected]
  • 2. Agenda • Array • Class/Object • Inheritance • Abstract Class • Overridden Methods • Interface • Polymorphism
  • 3. Array • int[] a = new int[10]; a[0]=10; a[1]=20; a[9]=45; • double[] d = new double[5][10]; d[0][0]=9.9; d[0][1]=3.14; a[4][9]=9.8;
  • 4. Class/Object public class Aclass { public Aclass(){//it’s called constructor Bclass b = new Bclass(); //b is object/instance b.hello(); //b invokes hello() method } public static void main(String[] args){ new Aclass(); } } class Bclass { public void hello(){ //hello() is a method System.out.print("Hello Everyone"); } }
  • 6. Inheritance public class Child extends Parent{ public Child(){ System.out.println(money); System.out.println(gold); System.out.println(rich()); System.out.println(job()); } public static void main(String[] args){ new Child(); } } class Parent{ public double money = 500000; public double gold = 200; public boolean rich(){ return true; } public String job(){ return "Doctor"; } }
  • 7. Abstract class in UML Diagram Duck <<abstract>> Bird Swallow
  • 8. Abstract Class public abstract class Bird { public String color; public abstract boolean isFlyable(); public void sound(){ System.out.println("Default”); } } class Duck extends Bird{ public boolean isFlyable() { return false; } public void sound(){ System.out.println("Quack "); } } class Swallow extends Bird{ public boolean isFlyable() { return true; } } Overridden Method
  • 9. Interface public interface Flyable { public String fly(); } class Chicken implements Flyable{ @Override public String fly() { return "Low and near"; } } class Swallow implements Flyable{ @Override public String fly() { return "High and far"; } }Chicken <<interface>> Flyable Swallow
  • 10. Abstract class vs Interface (Same) Abstract class • All subclasses of the abstract class have to override all abstract methods. • You cannot use new operator to create an instance from an abstract class. Bird b = new Bird(); • Abstract class can be used as a type. Bird b; Interface • All classes implemented the interface have to override all methods. • You cannot use new operator to create an instance from an interface. Flyable fly = new Flyable(); • Interface can be used as a type. Flyable fly;
  • 11. Abstract class vs Interface (Different) Abstract class • To declare an abstract class, use abstract keyword. public abstract class B{ } • A class can extend only one abstract class. class A extends B{ } • In relationship, we say A is B. Interface • To declare an interface, use abstract keyword. public interface B{ } • A class can implement more than one interface. class A implements C, D, E{ } • In relationship, we A has C, D, and E.
  • 12. Polymorphism What is polymorphism? • Polymorphism is a mechanism to allow a single variable to refer to objects from different classes.
  • 13. Polymorphism public class MyPoly { public static void main(String[] args) { Bird b; // b is Bird b = new Duck(); // b refers to Duck b.sound(); // b invokes Duck’s sound b = new Chick(); // b refers to Chick b.sound(); //b invokes Chick’s sound } } abstract class Bird{ public abstract void sound(); } class Duck extends Bird{ public void sound(){ System.out.println("Quack"); } } class Chick extends Bird{ public void sound(){ System.out.println("Cheep"); } }
  • 14. Go on the next slide