+ 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
4 Antworten
+ 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)
+ 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...
0
Thank you its understandable
0
No problem! I would have gone into more detail but I was exhausted lol. Let me know if you have anymore questions!