+ 2
Edititing an inheritance
can I edit or add to inheritance after I call from another class?
9 Answers
+ 3
class dog extends animal {
@Override
public void eat() {
s.o.p.("playing");
}
}
+ 4
I don't understand the question.
Can you give an example?
+ 2
yes, you can. This called Overriding.
In the child class create a method with the same signature and add @Override annotation.
+ 2
example of overriding:
class Animal {
public void eat() {
// override this please
System.out.println("eat what?");
}
}
class Rabit extends Animal {
@override
public void eat() {
System.out.println("eat carrots");
}
}
method eat() of class Rabit overrides the inherited eat() method of parent class Animal.
when you understand this example, you can try to improve by making Animal class abstract.
0
mmmm
class animal{
public void eat{
s.o.p ("eating");
}
}
class dog extends animal{
\\ can I do edit or add to eat method ?
0
could you plz get me an e.g.
and thnx
0
it's crystal now
thnx bro
0
so the output will be
"eat what?eat carrots"or just eat carrots