Kushtrim Kushtrim - 5 months ago 14
Java Question

How to propertly extend from superclass

I am totally new to java and tried to create a simple command line application but I am doing smth so wrong and I am not realizing it. Here's my code

public class Auto1 {
private String make;
private String model;
private int value;
private int soldPrice;
private int year;
private int hp;

public Auto1(String make, String model, int value, int soldPrice, int year, int hp) {
this.make = make;
this.model = model;
this.value = value;
this.soldPrice= soldPrice;
this.year = year;
this.hp = hp;

public void setMake(String a) {
make = a;
public void setModel(String b) {
model = b;
public void setvalue(int c) {
value = c;
public void setSoldPrice(int d) {
soldPrice = d;
public void setYear(int e) {
year = e;
public void setHp(int f) {
hp = f;
public String getMake() {
return make;
public String getModel() {
return model;
public int getValue() {
return value;
public int getSoldPrice() {
return soldPrice;
public int getYear() {
return year;
public void price() {
int price = value - soldPrice;
if(a >=5000) {
System.out.println("You Overpaid");
} else {
System.out.println("Fair Price");

And I am trying to create a subclass in which I would create this code

public class Auto extends Auto1{
Auto1 auto;
public auto = ("Audi","R8",162900,200000,2017,610){}

However it is not allowing me because "public" is an illegal start of type apparently and I don't know how else to create an object. Sorry if this sounds stupid to anyone but I'm very new to Java.


Your line public auto = ("Audi","R8",162900,200000,2017,610){} is not valid Java syntax. Did you mean to put this in your constructor? It looks like your class Auto is a more specific version than Auto1, namely one that refers to a specific "kind" of Auto1.

public Auto()