Anisafitriana89's Blog
Just another WordPress.com weblog

Tugas Java 2

Super class

Kendaraan.java
public class Kendaraan {

private String Roda;
private String Kemudi;
private String Sadel;

public Kendaraan (String Roda, String Kemudi, String Sadel)
{
this.Roda = Roda;
this.Kemudi = Kemudi;
this.Sadel = Sadel;

}
public void info()
{
System.out.println(“Kendaraan mempunyai : ” + this.Roda);
System.out.println(“Kendaraan mempunyai : ” + this.Kemudi);
System.out.println(“Kendaraan mempunyai : ” + this.Sadel);

}
}

Sub class Motor & Mobil

Motor.java

public class Motor extends Kendaraan
{
private static int jmlRoda = 2;
public Motor (String Roda, String Kemudi, String Sadel, int jmlRoda)
{
super (Roda, Kemudi, Sadel);
jmlRoda++;
}
public void info()
{
System.out.println(“Jumlah Roda : ” + jmlRoda);
super.info();
}
}

MotorTest.java

public class MotorTest
{

public static void main(String[] args)
{
Motor obj1 = new Motor(“Roda”,”Kemudi”,”Sadel”,2);
obj1.info();

System.out.println(“Method tambahan Jumping”);
}
}

Mobil.java

public class Mobil extends Kendaraan
{
private static int jmlRoda = 4;
public Mobil (String Roda, String Kemudi, String Sadel, int jmlRoda)
{
super (Roda, Kemudi, Sadel);
jmlRoda++;
}
public void info()
{
System.out.println(“Jumlah Roda : ” + jmlRoda);
super.info();
}
}

MobilTest.java

public class MobilTest
{

public static void main(String[] args)
{
Mobil obj1 = new Mobil(“Roda”,”Kemudi”,”Sadel”,4);
obj1.info();

System.out.println(“Method tambahan mundur”);
}
}

Output :

Output Motor

Jumlah Roda = 2

Kendaraan mempunyai = Roda

Kendaraan mempunyai = Kemudi

Kendaraan mempunyai = Sadel

Method tambahan Jumping

Output Mobil

Jumlah Roda = 4

Kendaraan mempunyai = Roda

Kendaraan mempunyai = Kemudi

Kendaraan mempunyai = Sadel

Method tambahan Mundur

No Responses to “Tugas Java 2”

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

%d bloggers like this: