a

Saturday 25 May 2013

Abstract Class

Class Abstrak tidak berbeda dengan class – class lainnya yaitu memiliki class members (method dan variabel). Sebuah class adalah abstrak jika salah satu methodnya dideklarasikan abstrak. Method abstrak adalah method yang tidak memiliki implementasi. Contoh deklarasi method abstrak:
abstract public void cetak();
Beberapa hal yang perlu diperhatikan adalah sebagai berikut:
  1. Class abstrak tidak dapat dibuatkan instan atau objeknya menggunakan keyword new.
  2. Sebuah class dapat dideklarasikan sebagai class abstrak walaupun tidak memiliki method abstrak.
  3. Variabel dengan tipe class abstrak tetap bisa diciptakan, tetapi harus refer ke subclass dari class abtrak tersebut yang tentunya tidak abstrak.
Perhatikan contoh class abstrak di bawah ini.
abstrak public class Mobil {
 public void injakPedalGas();
 public void injakRem(){
    System.out.println(“Mobil berhenti!”);
 }
}
public class Kijang extends Mobil{
 public void injakPedalGas(){
  System.out.println("Mobil Melaju dengan kecepatan 80 Km/jam...");
 }
}
public class BMW extends Mobil {
   public void injakPedalGas(){
    System.out.println("Mobil Melaju dengan kecepatan 100 Km/jam...");
 }
}


Objek class abtrak tidak dapat diciptakan menggunakan keyword new secara langsung. Apabila kita terpaksa ingin menciptakan object class abtrak tanpa membuat subclass kongkritnya, maka kita harus mengimplementasikan method – method abstraknya secara langsung saat deklarasi. Perhatikan contoh di bawah ini.
public class TestMobil {
 public static void main(String[] args){
  Mobil mobil = new Mobil(){
   public void injakPedalGas(){
    System.out.println("Mobil berjalan...");
   }
  };
  
  Kijang kijang = new Kijang();
  Escudo escudo = new Escudo();
  BMW bmw = new BMW();
  
  mobil.injakPedalGas();
  
  mobil = kijang;
  mobil.injakPedalGas();
  
  mobil = escudo;
  mobil.injakPedalGas();
  
  mobil = bmw;
  mobil.injakPedalGas();
 }
}

2 comments:

  1. Pretty nice post. I just stumbled upon your weblog and wished to say that
    I have truly enjoyed browsing your blog posts. In any case I'll be subscribing to your rss feed and I hope you write again soon!

    my web site Books Of ra online

    ReplyDelete
  2. payday loans online How To Come Across The Dollars Owed To
    You
    Insurance plan - There are tons of insurance policy product sales positions out there that only involve a certification and not a college or
    university diploma. Not like numerous profits positions, a
    whole lot of coverage positions have no income cap. If you are enthusiastic
    to function, this is an location to get paid in.


    Past but not the the very least, mining is a single of
    the most well-known methods to receive payday loans online.
    If you want get promotion, you would superior choose iron and
    coal, which has substantial comments. Coal has been scarcity and by no means
    be offer off. If you are no acquiring 65+,
    you really should not to pluck mrthril, mainly because you may
    get reduce working experience details.
    If so, here is a potent instrument that has been and nevertheless is utilized by many good men and
    women and can Warranty your accomplishment!
    It is called "autosuggestion" and it is a mystery system for directing
    the sub-aware to transfer forward on specified facts presented to it on car-pilot.


    The responses you get from these dependable sources are normally
    accurate. There may possibly be some times where by the information and facts might not be what you just need.
    So, it is significant to search for out people internet sites that have some sort of assurance about their responses.
    But you can operate with the web site and the professional to make clear or to amplify the reply that they give.

    The Indian postal sector offers quite a few publish workplace
    price savings techniques. The cost savings schemes incorporate conserving
    account strategies, recurring deposit strategies, time deposit strategies, Regular monthly
    Income Strategies (MIS), Community Provident Fund Schemes (PPF), Countrywide Financial savings Certificate (NSC) and
    a lot of extra. With RBI deregulating curiosity costs on price savings
    deposits, the Authorities of India also hiked the desire
    price on put up place of work personal savings scheme to
    4% from three.5%.
    There are lots of debt consolidation management corporations which
    advises you the measures which you can just take to more than come and management your debts.

    These providers presents you credit rating counseling,
    prepares credit card debt consolidation management strategies for
    you, counseling on avoiding personal bankruptcy and other such companies.
    To implement for finding credit card debt consolidation advising companies,
    you are required to fill the requisite particulars in the type these kinds of as your name, deal with and contact details alongside with the
    amount and total of money owed you are carrying,
    your money.
    A person vital facet of the factors you need to recall with your blog site is to get pleasure from the knowledge!

    Weblog Submitting can get unexciting and be uninteresting to any audience if you will not experience passionate about your matter.

    Come across a enjoyment topic that you really like to write about!
    If you have a excellent time writing the blog, some others will get caught
    up in your enthusiasm as nicely.
    If you elect to use pop-up windows on your blog, be confident that they are
    ready to load after the rest of our information does,
    so visitors do not have to battle off pop-ups in lieu of
    examining your written content.

    ReplyDelete