Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //filename TestInheritance.java
- public class TestInheritance {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Teks t1 = new Teks();
- t1.setTing(5);
- int t=t1.getTing();
- t1.setTajuk("Sejarah");
- String tajuk=t1.getTajuk();
- }
- }//class main
- class Buku{
- private String tajuk;
- private String ISBN;
- private double harga;
- private String pengarang;
- private String penerbit;
- public String getTajuk(){
- return pengarang;
- }
- public void setTajuk(String tajukbuku){
- tajuk=tajukbuku;
- }
- }//end class Buku
- class Teks extends Buku{
- private int tingkatan;
- public int getTing(){
- return tingkatan;
- }
- public void setTing(int ting){
- tingkatan=ting;
- }
- }//end subclass Teks
- class Cerpen extends Buku{
- private String genre;
- public String getGenre(){
- return genre;
- }
- public void setGenre(String gen){
- genre=gen;
- }
- }//end subclass Cerpen
Advertisement
Add Comment
Please, Sign In to add comment