Home > Pemprograman > Lesson 1 – Basic Java (Starting,Control,looping) – Part 2

Lesson 1 – Basic Java (Starting,Control,looping) – Part 2

after we learn ‘class’ , we will learn about instance , polymorphisme and encapsulation. Let’s begin our class

1. Instance

instance is a process to create class into object. before become an object, class is basic. the pattern is :

class_name object_name = new constructor();

for instance : Octav octav = new Octav();

we declare object octav is given from class Octav. it’s different between Octav and octav. here the example :

class Bike
 public void stang()
  System.out.println(“My Name is Octav”);
 public class Car
  public static void main(String[] args)
  Bike bike = new Bike();


output : “My name is Octav”

2. Polymorfisme

polymorfisme is many morph in one name of method in same time. for example :

public void setNama(String a) {}

public void setNama(){}

public void setNama(String a,String b){}

public void setNama(int a){}

we can use setNama method and its depend from your choice. like that :

public void static main(String[] args)




because setNama(5) is integer type, so it will pass ‘public void setNama(int a)’ .

3. Encapsulation

is the abillity of OOP can encapsul or hide how to work from end user. so it’s will be hide, and information will secret. here the example :

class Ambil


private String a;

public setNama(String a)


this.a = a;


public getNama()


return (nama+" pratama");



public class Nama


public void static main(String[] args)


Ambil am = new Ambil();


System.out.println("Your Name : "+am.getNama());



output : “Your Name Octav Pratama”

we didn’t know why there is a word ‘Pratama’, because. it’s a encapsulation.

user input Octav and output Octav Pratama.

we will meet in next lesson about Control and looping in part 3

Categories: Pemprograman
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s