“Exemplo de herança de java” Respostas de código

Herança Java


public class Sample {
    public static void main(String[] args) {
        Dog dog = new Dog();
        Cat cat = new Cat();
        Duck duck = new Duck();
        System.out.println(dog.getSound());
        System.out.println(cat.getSound());
        System.out.println(duck.getSound());
    }
}

class Animal {
    private String sound = "anything";

    public void setSound(String sound) {
        this.sound = sound;
    }

    public String getSound() {
        return sound;
    }
}

class Dog extends Animal {
    private String sound = "Aw aw";

    public String getSound() {
        return sound;
    }
}

class Cat extends Animal {
    private String sound = "Meow meow";

    public String getSound() {
        return sound;
    }
}

class Duck extends Animal {
    private String sound = "Quack Quack";

    public String getSound() {
        return sound;
    }
}
Fernandez, Jasmine M.

o que é herança em java

Inheritance is the mechanism where the object of one class acquires the property of the object of another class.
Disturbed Dog

herança em java

Inheritance in Java is a mechanism in which one object acquires 
all the properties and behaviors of a parent object.
It is an important part of OOPs (Object Oriented programming system).
Gentle Goat

Herança em java

Java Inheritance (Subclass and Superclass)
In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories:

subclass (child) - the class that inherits from another class
superclass (parent) - the class being inherited from
To inherit from a class, use the extends keyword.
Santino

Exemplo de herança de java

public class Parent
{
  //methods and constructors 
}

public class Child extends Parent
{
	//inherits methods from Parent class
}
Christina Zhang

Herança em java

Super class:
public class Multi(){
}
Sub class:
public class Multiplication extends Maltil(){
}
Outrageous Ostrich

Respostas semelhantes a “Exemplo de herança de java”

Perguntas semelhantes a “Exemplo de herança de java”

Mais respostas relacionadas para “Exemplo de herança de java” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código