+ 2

What is the meaning of adding characteristics and behaviour in a subclass of superclass

What does adding characteristics and behaviour in java by means of inheritance mean Also tell me what is the problem with this code https://code.sololearn.com/cUEp7ahI3jTa/?ref=app

13th Mar 2019, 1:15 PM
Rajb957
Rajb957 - avatar
4 ответов
+ 1
// Inspired by Raj Bunsha public class Program extends Program2 { public static void main(String[] args) { toPrint();//Calling the Program2s' toPrint method. } } public class Program2 { protected static void toPrint() { int a = 5;//Making a equal to 5 System.out.println(a);//Printing out a, which is holding the int vale of 5 } } I reorganized your code a bit. In this example the program2 only has a behavior, when they say behavior they mean the class's method (because methods determine how something runs or acts, per say like a Car class would have a start engine method, and or a accelerate method) and when they say characteristics they mean the variables (for example a Car class would have variables like color, model, price, speed)
15th Mar 2019, 2:47 AM
Amber Janosh
Amber Janosh - avatar
+ 4
I don't do Java so I can't help you thoroughly; but two things, both in line 4: 1.) You have a typo in your method name. 2.) You can't access 'a' from there. I hope you'll get help with the inheritance details...
13th Mar 2019, 2:39 PM
HonFu
HonFu - avatar
0
Thank you its understandable
15th Mar 2019, 9:16 AM
Rajb957
Rajb957 - avatar
0
No problem! I would have gone into more detail but I was exhausted lol. Let me know if you have anymore questions!
15th Mar 2019, 12:16 PM
Amber Janosh
Amber Janosh - avatar