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!"); } }
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.
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.
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🇮🇳
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)
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.
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)
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
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