+ 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(); } }

8th Jan 2018, 10:40 PM
Jaren Dogan
Jaren Dogan - avatar
7 Answers
+ 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); } }
9th Jan 2018, 10:27 AM
D_Stark
D_Stark - avatar
+ 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
8th Jan 2018, 10:49 PM
Dapper Mink
Dapper Mink - avatar
+ 4
@Jaren Your welcome â˜ș
10th Jan 2018, 9:45 AM
D_Stark
D_Stark - avatar
+ 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
9th Jan 2018, 12:01 AM
Dan Walker
Dan Walker - avatar
+ 1
thanks for helping me out, I appreciate it
9th Jan 2018, 4:39 PM
Jaren Dogan
Jaren Dogan - avatar
0
I'm still confused, what is look like Airplane Boeing; or Boeing = Airplane ();
8th Jan 2018, 11:16 PM
Jaren Dogan
Jaren Dogan - avatar
0
thanks but I still don't Understand the last part. a1.Boeing, how is it meaningless?
9th Jan 2018, 1:17 AM
Jaren Dogan
Jaren Dogan - avatar