Created
November 9, 2018 00:34
-
-
Save shalahuddinn/8f6ca55312339cb32bd27cd354890cdf to your computer and use it in GitHub Desktop.
Divkom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Percobaan 1 | |
*/ | |
public class Dog { | |
// Instance Variables | |
String breed; | |
String size; | |
int age; | |
String color; | |
// method 1 | |
public String getInfo() { | |
return ("Breed is: "+breed+" Size is:"+size+" Age is:"+age+" color is: "+color); | |
} | |
} | |
public class mainProgram { | |
public static void main(String[] args) { | |
Dog maltese = new Dog(); | |
maltese.breed="Maltese"; | |
maltese.size="Small"; | |
maltese.age=2; | |
maltese.color="white"; | |
System.out.println(maltese.getInfo()); | |
} | |
} | |
/* | |
* Percobaan 2 | |
*/ | |
public class Animal { | |
private String eats; | |
private int noOfLegs; | |
public Animal(){} | |
public Animal(String food, int legs){ | |
this.eats = food; | |
this.noOfLegs = legs; | |
} | |
public String getEats() { | |
return eats; | |
} | |
public void setEats(String eats) { | |
this.eats = eats; | |
} | |
public int getNoOfLegs() { | |
return noOfLegs; | |
} | |
public void setNoOfLegs(int noOfLegs) { | |
this.noOfLegs = noOfLegs; | |
} | |
} | |
public class Cat extends Animal{ | |
private String color; | |
public Cat(String food, int legs) { | |
super(food, legs); | |
this.color="White"; | |
} | |
public Cat(String food, int legs,String color){ | |
super(food, legs); | |
this.color=color; | |
} | |
public String getColor() { | |
return color; | |
} | |
public void setColor(String color) { | |
this.color = color; | |
} | |
} | |
public class MainProgram { | |
public static void main(String[] args) { | |
//Cat garong = new Cat("ikan", 4, "coklat"); | |
Cat garong = new Cat("ayam", 4); | |
System.out.println("Eats: "+garong.getEats()); | |
System.out.println("No of legs: "+garong.getNoOfLegs()); | |
System.out.println("Color: "+garong.getColor()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment