Java Programming Tutorial - 31 - Inheritance, Abstract Classes and Abstract Methods

preview_player
Показать описание
Video describing inheritance in Java, using abstract classes, concrete classes and abstract methods.
Рекомендации по теме
Комментарии
Автор

public class Main {

public static void main(String[] args) {

Dog myDog = new Dog("Spike", 2);
Cat myCat = new Cat("Fluffy", 3);

myDog.speak();
myCat.speak();

}
}






public abstract class Pet {

protected String name;
protected int age;

public Pet(String name, int age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public abstract void speak();


}







public class Dog extends Pet {

public Dog(String name, int age, boolean hasLicense) {
super(name, age, hasLicense);
}

@Override
public void speak() {
System.out.println(this.name + " said bark bark!");
}


}











public class Cat extends Pet {

public Cat(String name, int age, boolean hasLicense) {
super(name, age, hasLicense);
}

@Override
public void speak() {
System.out.println(this.name + " said meowww!");
}

}

UniProgrammer
Автор

This is gold! all my doubts about inheritance and abstract class are solved after watching this.

monojitchakraborty
Автор

Hi, thank you so much. I am preparing for my OCA Exam and watching this video really helped. Keep up doing what you do best

nelisiwecynthia
Автор

University of the People sent me here, and this is a far better explanation than the one they gave.

QFGEE
Автор

Thanks mate, solved an issue I was having. Just didn't notice the problem, following correct steps made me realize how stupid the mistake was :)

riddlediddleriddle
Автор

Thank you bro, you explain things clearly and at a good pace, I was following derek banas tutos but the guy explain things like he is in a race, even though he is good.

jamesacheneider
Автор

very professional and informative video keep it up

karentechnologies
Автор

Thank you. I’m worshiping the wall as we speak. A mistake I made was not using “this.*property=property” in a program I was making. I was stuck for a good 4 hours. (Could’ve been more effective but didn’t really care.) Thank you. Fixed my problem.

jamesmonto
Автор

Hey Andru, Thanks Alot...My concept are cleared in very easy manner through your video. Will definately refer your videos and channel as well. Stay blessed.
Love From India🇮🇳

vaibhavwaghole
Автор

Good day Man. I really love your videos, just a quick question. Can a method be accessed from a subclass of an inherited class that is (This method should be different from the method of it's superclass)

shephardstudio
Автор

Thank you for this video, it will help me with my assignment!!!

MaruBaku
Автор

Hi Andrew, Are you still making Java tutorials? I would like to ask you many questions about it, as I find your way of teaching very helpful to me. But I see you didn't add since 2018. Now we are 2021....How can I contact you? Nina

ninaalexieva
Автор

One question that I have is why to use abstract methods when we already know that we are going to need to make a method in the instance and probably already knows what the method should do?

I mean, for me, it makes more sense to make a non-static method speak() inside the Pet abstract class and make it generic for all the subclasses (name and age for parameters so when you call the speak method you just need to pass the name and age as arguments), and if you want to change the speak method inside a subclass, you just override in that subclass.

dedz
Автор

Hello! I was wondering if an accessor method can be an abstract method, because I'm making an abstract Coin class and the super classes under it has different values (for example the value of toonie is 2.0)

nyanpie
Автор

Really helpful, thanks a lot brother <33

naveedasgari
Автор

define abstract class Hospital with protected member id and name

define a parameterized constructor. define a sub class Doctor with

member department. Create n objects of Doctor and display all details.
I want ans of this question

mehndiart
join shbcf.ru