I have created a superclass Airplanes and a subclass Gliders
public class Airplanes
{
public String hasWings;
public int numberWheels;
public int numberPassengers;
public Airplanes(String hasWings, int numberWheels, int numberPassengers)
{
// initialise instance variables
this.hasWings=hasWings;
this.numberWheels=numberWheels;
this.numberPassengers=numberPassengers;
}
}
and
public class Gliders extends Airplanes
{
private String hasEngine;
public Gliders(String hasWings,int numberWheels,int numberPassengers,String hasEngine)
{
super(hasWings,numberWheels,numberPassengers);
this.hasEngine=hasEngine;
}
public void getSpec()
{
System.out.println("Glider With wings: " + super.hasWings);
System.out.println("Glider Wheels: " + super.numberWheels);
System.out.println("Glider Number of passenger: " + super.numberPassengers);
System.out.println("Glider has engine: " + hasEngine);
}
}
A new class test has to initialise Gliders and is written like this:
public class Test
{
public Test()
{
Airplanes alfa = new Gliders("Yes",2,2,"Np");
Gliders.getSpec();
}
}
When i try to run Gliders.getSpec() it prints an error saying that i'm trying to reference a non static method from a static context.
I'm just wondering if what i'm trying to do is legal or not, and if it is how can i fix it?