+ 3
Why can't i do this on Java - Boeing = new Airplane ();? I wasn't done with the code by the way.
class Airplane { int maxSpeed; int distance; int wings; String captain; double fuelcapacity; class Boeing extends Airplane { protected int flight; public void Boeing() { System.out.println("5,4,3,2,1, we are ready to take flight"); } } } class Program { public static void main(String[] args) { Boeing = new Airplane(); Boeing a1 = new Airplane(); Boeing a2 = new Airplane(); a1.Boeing(); } }
7 Antworten
+ 8
/* I have fixed your code you had your brackets {} in the muddled up here we have created a boeing plane that has all the properties of airplane */
public class Airplane {
int maxSpeed;
int distance;
int wings;
String captain;
double fuelcapacity;
}
public class Boeing extends Airplane {
protected int flight;
public void Boeing() {
System.out.println("5,4,3,2,1, we are ready to take flight");
}}
public class Program {
public static void main(String[] args) {
Boeing plane1 = new Boeing();
plane1.Boeing();
plane1.captain = "\nCaptain: David ^_^";
System.out.print(plane1.captain);
}
}
+ 4
You have to give it a name
It's the same as if you wrote "int = 3", you create an integer equals to 3 but you need to name your variable so that you have a reference of where your value is stored
+ 4
@Jaren Your welcome ☺
+ 1
You should do Airplane myPlane = new Boeing()
You can always do a superclass/interface on the left, we are saying here that a Boeing is and Airplane. We can't say that our Airplane is a Boeing (it might be another type of plane).
Further, a child class implicitly calls its parent constructor, so as it stands it doesn't make sense in Java terms.
also a1.Boeing() is meaningless
+ 1
thanks for helping me out, I appreciate it
0
I'm still confused, what is look like Airplane Boeing;
or Boeing = Airplane ();
0
thanks but I still don't Understand the last part. a1.Boeing, how is it meaningless?