Professional Documents
Culture Documents
ABSTRACT CLASS
A. OBJECTIVE
Understanding abstract definition as a mechanism that allow you to make some
method in class but not with the definition, and how to use abstract class in java.
B. BASIC TEORY
Abstract is some mechanism that allow you to make some method in class but not
with the definition. The definition class specified by each inheritance class. In this
term each inheritance of abstract class need to define methods which is included as
abstract class.
C. TOOLS
1. Laptop
2. Software NetBeans
D. EXPERIMENT
WORK STEP
1. Create new class named as Kendaraan.java, write the program as following
public abstract class Kendaraan {
protected String nama; //variable lokal
public abstract void jalankan(); //abstact method
}
2. Save file with name of the class.
3. Next make new class named as Sepeda.java, write the program as following
public class Sepeda extends Kendaraan{
public Sepeda (String nama){
this.nama = nama;
}
public void jalankan (){
System.out.println("Duduklah diatas Sadel "+this.nama+" dan kayuhlah");
}
}
4. Save file with name of the class
5. Then create new class with main method which is the class sepeda
implementation
public class TesAbstrakSepeda {
EXERCISES
1. Create new class named as Mobil.java, which is subclass from kendaraan and
Solution:
Complite source code
public class Mobil extends Kendaraan {
public Mobil(String jenis){
this.nama = jenis;
}
public void jalankan(){
System.out.println("Duduk di depan Setir "+this.nama+
" dan Hidupkan mesin");
}
public void bunyikanTlakson(){
E. ANALYSIS
There is no error in Kendaraan.java even though there is a method (jalankan())
having no definition and then the method defined in Sepeda.java as subclass of
Kendaraan.java. it shows that abstract can be created and probably it has been
known that the subclasses are fit operation with the method but one and another
subclass has different action.