oop concept 1 abstraction oop concept 2 encapsulation oop...

Post on 15-Aug-2019

251 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

OOP Concept 1 Abstraction

OOP Concept 2 Encapsulation

OOP Concept 3 Inheritance

Constructor

OOP Concept 4 Polymorphism

The way we look at a system in a simpler form, that is as a collection of subsystems (object) that interact with each other. For Example:

Car is a collection of ignition system, steering system, braking system

Tool to abstract something is class.

Object is modularity. Object can be written and maintained separately(independently) from another object.

Mechanism to hide a process in the system to avoid

interference and simplify the use of the system itself. For Example:

Transmission rod (gear) on the car.

The on / off / on the air conditioning temperature setting.

Class access levels (public, protected, private) is the implementation of the concept of encapsulation.

Sumber:http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html Contoh lain: Abdul kadir Dasar Pemrograman Java 2 Hal 149-154 dan 177-179

A class can inherit attributes and methods in another

class (subclass), and forming class hierarchy.

Consist of:

Superclass (parent)

Subclass (child)

Important for reusability.

Java keyword: extends.

A subclass inherits all the members

(fields, methods, and nested classes) from its superclass. Constructors are not

members, but the constructor of the superclass can be invoked from the subclass.

• MountainBike inherits all the fields and methods of

Bicycle and adds the field seatHeight and a method to set it.

Method used for the initial value at the

time the object was created.

Called automatically when the keyword "new" is used to make instant class

Character of the constructor:

Constructor name same with name of the class

Has no return value and there should be no void keyword.

your method overrides superclass's methods

invoke the overridden super

The inherited fields can be used directly, just like

any other fields.

You can declare a field in the subclass with the same name as the one in the superclass, thus

hiding it (not recommended).

You can declare new fields in the subclass that are not in the superclass.

The inherited methods can be used directly as

they are.

You can write a new instance method in the subclass that has the same signature as the one in the superclass, thus overriding it.

You can write a new static method in the

subclass that has the same signature as the one in the superclass, thus hiding it.

You can declare new methods in the subclass

that are not in the superclass.

You can write a subclass constructor that invokes the constructor of the superclass, either implicitly or by using the keyword super.

The dictionary definition of polymorphism refers to a

principle in biology in which an organism or species can have many different forms or stages.

This principle can also be applied to object-oriented

programming and languages like the Java language.

Subclasses of a class can define their own unique

behaviors and but share some of the same functionality of the parent class.

In shorthand “an object can have various shapes”.

Implementation of the concept of polymorphism:

Overloading: The use of one name for several method with different parameter.

Overriding: Occurs when a subclass method declaration exactly same as the method of the superclass.

Contact: moses.dinus@gmail.com

top related