khirulnizam

Inheritance Buku

Jul 2nd, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. //filename TestInheritance.java
  2. public class TestInheritance {
  3.  
  4.     public static void main(String[] args) {
  5.         // TODO Auto-generated method stub
  6.         Teks t1 = new Teks();
  7.         t1.setTing(5);
  8.         int t=t1.getTing();
  9.         t1.setTajuk("Sejarah");
  10.         String tajuk=t1.getTajuk();
  11.     }
  12. }//class main
  13.  
  14. class Buku{
  15.     private String tajuk;
  16.     private String ISBN;
  17.     private double harga;
  18.     private String pengarang;
  19.     private String penerbit;
  20.    
  21.     public String getTajuk(){
  22.         return pengarang;
  23.     }
  24.     public void setTajuk(String tajukbuku){
  25.         tajuk=tajukbuku;
  26.     }
  27. }//end class Buku
  28.  
  29. class Teks extends Buku{
  30.     private int tingkatan;
  31.     public int getTing(){
  32.         return tingkatan;
  33.     }
  34.     public void setTing(int ting){
  35.         tingkatan=ting;
  36.     }
  37. }//end subclass Teks
  38.  
  39. class Cerpen extends Buku{
  40.     private String genre;
  41.     public String getGenre(){
  42.         return genre;
  43.     }
  44.     public void setGenre(String gen){
  45.         genre=gen;
  46.     }
  47. }//end subclass Cerpen
Advertisement
Add Comment
Please, Sign In to add comment