Select Menu

Search This Blog

Populer Posts Hari ini

Popular Posts

Powered by Blogger.

Lorem 1

adsense

" });

Circle Gallery

" });

News

" });
» » » » Source code konsep inheritance (pewarisan sifat objek) with Java

Kali saya akan berbagi source code konsep inheritance atau pewarisan sifat pada objek menggunakan bahasa Java.

package konsepinheritance;
class A{
    private int a;
    public void Seta(int nilai){
        a=nilai;
    }
    public int Geta(){
        return a;
    }
}

class B extends A{
    private int b;
    public void setb(int nilai){
        b=nilai;
    }
    public int Getb(){
    return b;
    }
}

/**
 *
 * @author andi m
 */
public class KonsepInheritance {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        B obj=new B();
        obj.Seta(100);
        obj.setb(200);
        System.out.println("nilai objek a:\t"+obj.Geta());
        System.out.println("nilai objek b:\t"+obj.Getb());
    }
   
}

About andi

«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply