Minggu, 11 Desember 2011

DEKLARASI INTERFACE

Interface adalah class yang method - methodnya hanya deklarasi saja, semua methodnya public dan abstact, variable bersifat static final yang disebut konstanta

interface PersonDao{}

interface PersonDao
interface PersonDao{
        void save(Person p);
        void delete(person p);
        Person getById(Long id);
}

class PersonDao
public class PersonDao{
        private Long id;
        private String nama;

        public void setId(Long i){
                id=i;
        }

         public Long getId(){
                 return id;
         }

          public void setNama(String n){
                  nama = n;
          }

           public String getNama(){
                   return nama;
           }
}

class implementasi PersonDao
public class PersonDaoImpl implements PersonDao{
           public void save(Person p){
                     System.out.println("save person");
            }
            
            public void delete(Person p){
                      System.out.println("delete person");
            }

             public Person getById(Long id){
                       Person p = new Person();
                       p.setId = (id);
                       p.setNama = ("nama");
                       return p;
             }
}

implementasi interface boleh lebih dari satu interface

Tidak ada komentar:

Posting Komentar