+ 2

Edititing an inheritance

can I edit or add to inheritance after I call from another class?

9th Aug 2017, 4:17 AM
Hmmam Babe khuoja
Hmmam Babe khuoja - avatar
9 ответов
+ 3
class dog extends animal { @Override public void eat() { s.o.p.("playing"); } }
9th Aug 2017, 6:20 AM
Roman
Roman - avatar
+ 4
I don't understand the question. Can you give an example?
9th Aug 2017, 4:35 AM
Rrestoring faith
Rrestoring faith - avatar
+ 2
yes, you can. This called Overriding. In the child class create a method with the same signature and add @Override annotation.
9th Aug 2017, 5:34 AM
Roman
Roman - avatar
+ 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.
9th Aug 2017, 6:26 AM
Roland Sterkendries
Roland Sterkendries - avatar
0
mmmm class animal{ public void eat{ s.o.p ("eating"); } } class dog extends animal{ \\ can I do edit or add to eat method ?
9th Aug 2017, 5:22 AM
Hmmam Babe khuoja
Hmmam Babe khuoja - avatar
0
could you plz get me an e.g. and thnx
9th Aug 2017, 6:18 AM
Hmmam Babe khuoja
Hmmam Babe khuoja - avatar
0
it's crystal now thnx bro
9th Aug 2017, 6:21 AM
Hmmam Babe khuoja
Hmmam Babe khuoja - avatar
0
so the output will be "eat what?eat carrots"or just eat carrots
9th Aug 2017, 6:54 AM
Hmmam Babe khuoja
Hmmam Babe khuoja - avatar