้ŸณใŒๆตใ‚Œใชใ„ๅ ดๅˆใ€ๅ†็”Ÿใ‚’ไธ€ๆ™‚ๅœๆญขใ—ใฆใ‚‚ใ†ไธ€ๅบฆๅ†็”Ÿใ—ใฆใฟใฆไธ‹ใ•ใ„ใ€‚
ใƒ„ใƒผใƒซใ€€
็”ปๅƒ
Bro Code
3568ๅ›žๅ†็”Ÿ
Learn INHERITANCE in 9 minutes! ๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ

#java #javatutorial #javacourse

00:00:00 inheritance
00:05:10 multi-level inheritance

public class Main {
public static void main(String[] args) {

// Inheritance = One class inherits the attributes and methods
// from another class.

Dog dog = new Dog();
Cat cat = new Cat();
Plant plant = new Plant();

}
}
public class Organism {

boolean isAlive;

Organism(){
isAlive = true;
}
}
public class Plant extends Organism{

void photosynthesize(){
System.out.println("The plant absorbs sunlight");
}
}
public class Animal extends Organism{

void eat(){
System.out.println("This animal is eating");
}
}
public class Dog extends Animal{

int lives = 1;

void speak(){
System.out.println("The dog goes *woof*");
}
}
public class Cat extends Animal{

int lives = 9;

void speak(){
System.out.println("The cat goes *meow*");
}
}

ใ‚ณใƒกใƒณใƒˆ