“Polimorfisme di Java” Kode Jawaban

Polimorfisme java

class Animal {
  public void animalSound() {
    System.out.println("The animal makes a sound");
  }
}

class Pig extends Animal {					//extends Animal
  public void animalSound() {
    System.out.println("The pig says: wee wee");
  }
}

class Dog extends Animal {					//extends Animal
  public void animalSound() {
    System.out.println("The dog says: bow wow");
  }
}

class Main {
  public static void main(String[] args) {
    Animal myAnimal = new Animal();  // Create a Animal object
    Animal myPig = new Pig();  // Create a Pig object
    Animal myDog = new Dog();  // Create a Dog object
    myAnimal.animalSound();
    myPig.animalSound();
    myDog.animalSound();
  }
}
Magnificent Monkey Adi

Polimorfisme di Java

Public class Multi(){ //Super class
public void multi(){
}
}
public class Multiplication extends Multi(){ // Sub class
public void multi(){
}
public static void main(String args[]){
Multi multiplication= new Multiplication();//Multi is reference type and Multiplication is reference type
multiplication.multi();
}
}
Outrageous Ostrich

Jawaban yang mirip dengan “Polimorfisme di Java”

Pertanyaan yang mirip dengan “Polimorfisme di Java”

Lebih banyak jawaban terkait untuk “Polimorfisme di Java” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya