0
Can help me please, I’m studying Java and I’m having the following mistakes:
Main.java:12: error: non-static variable carro1 cannot be referenced from a static context carro1 = new aut.automovel("Chevette", 87); ^ Main.java:12: error: package aut does not exist carro1 = new aut.automovel("Chevette", 87);
This program has three classes: Automoveis
, Main
and Motorista
.
import java.io.*;
public class Main
{
private Automoveis carro1;
private Motorista motorista1, motorista2;
public static void main(String[] args)
{
Automoveis aut = new Automoveis();
Motorista mot = new Motorista();
carro1 = new aut.automovel("Chevette", 87);
//carro1 = new aut.Automoveis("T",78);
aut.displayMessage("Teste");
//motorista1 = new mot.motorista("João", carro1);
//motorista2 = new mot.motorista("Pedro",carro1);
//System.out.println(motorista1.obterNome());
//System.out.println(motorista2.obterNome());
}
}
-
public class Automoveis
{
public String modelo;
public int ano;
private boolean ligado;
//Instanciar automaovel
public void automovel(String m, int a){
modelo = m;
ano = a;
ligado = false;
}
//Ligar automóvel
public void liga()
{
ligado = true;
}
public void desliga()
{
ligado = false;
}
public void displayMessage(String s)
{
System.out.println(s);
}
}
-
public class Motorista
{
private String nome;
private Automoveis carro;
//Instanciar motorista
public void motorista(String n, Automoveis a)
{
nome = n;
carro = a;
}
//Obter nome do motorista
public String obterNome()
{
return nome;
}
public Automoveis obterCarro()
{
return carro;
}
}
What I’m doing wrong?
Thanks in advance!
Solved, that was it. As for plural did not know, I will use from now on! Thanks.
– Bruno Souza
@Brunosouza If this answer solved your problem and there is no doubt left, click on the " " which is to the left of the answer to mark it as accepted/correct, which also marks your question as solved/answered. Otherwise, feel free to comment.
– Victor Stafusa