Tuesday, May 5, 2015

MODUL 5 : ABSTRACT CLASS


  1. Objectives 

    Objectives of making this report are : 
  1. Students are able to understand what the definition of Abstract Class in Java.
  2. Students are able to implement Abstract Class in this practical laboratory.

  1. Theoritical Basis
    Java provides a mecanism that make possible a method determined inside of class but it is not included the definition. This method known as Abstract Method and the class called Abstract Class. Definition of class determmined by the each inherited classes. In this case, each inherited class of Abstract Class must define methods that grouped as Abstract Method.

  1. Tool and Material
  1. Laptop
  2. Java Development Kit (JDK 8)
  3. NetBeans IDE 8.0.2

  1. Work Steps
  1. Experiment
  1. Creating a new classs named “Kendaraan.java” then writing the codes below :

package Percobaan1;

/**
 *
 * @author Jhonny
 */
public abstract class Kendaraan {
    protected String nama;
    public abstract void jalankan(); //method abstrack
}
  1. Saving and compiling as the name of the class.
  2. Next, creating a new class named “Sepeda.java” , writing the program codes below :

package Percobaan1;

/**
 *
 * @author Jhonny
 */
public class Sepeda extends Kendaraan{
    public Sepeda(String nama){
        this.nama = nama;
    }
    public void jalankan(){
        System.out.println("Duduklah di atas sadel "+ this.nama +" dan kayuhlah !");
    }
}
  1. Saving and compiling as the name of the class.
  2. Then, creating a new class with main( ) method that is implementation of “Sepeda” class. Writing this program codes inside of this class.

package Percobaan1;

/**
 *
 * @author Jhonny
 */
public class TesAbstrakSepeda {
    public static void main (String []args){
        Sepeda sepedaku = new Sepeda("Sepeda Ontel");
        sepedaku.jalankan();
    }
}
  1. Saving and compiling as the name of the class.
  2. Observing and noting the result


  1. Analysis
    Inside class of “Kendaraan.java” contains an Abstract Method that doesn’t have instructions yet. But inside of the subclass we have made, it is written the Abstract Method with instructions. Well, it works very good and get the result. An Abstract Class known that any subclasses are operations that match with the method but among one class and other classes have different treatments.


  1. Tasks
  1. Creating a new class named “Mobil.java” that is subclass of “Kendaraan” class and creating a new class named “TesAbstractMobil.java” as implementation of “Mobil.java”.

package Percobaan1;

/**
 *
 * @author Jhonny
 */
public class Mobil extends Kendaraan {
    public Mobil(String nama){
        this.nama = nama;
    }
    public void jalankan(){
        System.out.println("Duduklah di depan dan setirlah " + this.nama + " dan Hidupkan Mesin !");
    }

package Percobaan1;

/**
 *
 * @author Jhonny
 */
public class TesAbstrakMobil {
    public static void main (String []args){
        Mobil mobilku = new Mobil("Mobil Tua");
        mobilku.jalankan();
        mobilku.bunyikanTlakson();
    }
}
  1. Following the steps above.
  2. Adding a new method inside class of “Mobil.java”.

package Percobaan1;

/**
 *
 * @author Jhonny
 */
public class Mobil extends Kendaraan {
    public Mobil(String nama){
        this.nama = nama;
    }
    public void jalankan(){
        System.out.println("Duduklah di depan dan setirlah " + this.nama + " dan Hidupkan Mesin !");
    }
    public void bunyikanTlakson(){
        System.out.println("Bunyikan Tlakson " + this.nama + " saat di Persimpangan !");
    }
}
  1. The result will be like this figure.

No comments:

Post a Comment