import java.util.ArrayList;
import sun.rmi.runtime.Log;
class Carro
{
private int portas;
private int km;
{
this.nome = nome;
this.portas = portas;
this.cor = cor;
this.km = km;
}
public String getNome
() { return nome
; } public int getPortas () { return portas; }
public String getCor
() { return cor
; } public int getKm () { return km; }
public void setNome
( String nome
) { this.
nome = nome
; } public void setPortas ( int portas ) { this.portas = portas; }
public void setCor
( String cor
) { this.
cor = cor
; } public void setKm ( int km ) { this.km = km; }
//Restantes métodos como clone, equals, compareTo, toString, etc..
}
class JavaApplication
{
public static void main
(String[] args
) {
Carro carro = new Carro("carro 1", 3, "preto", 120000);
Carro carro2 = new Carro("carro 2", 5, "verde", 143131);
ArrayList<Carro> listaDeCarros = new ArrayList<>();
listaDeCarros.add(carro);
listaDeCarros.add(carro2);
// Para percorrer o ArrayList:
for (Carro carro_temp : listaDeCarros)
{
System.
out.
println("carro:" + carro_temp.
getNome()); }
}
}
aW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7CmltcG9ydCBzdW4ucm1pLnJ1bnRpbWUuTG9nOwoKCmNsYXNzIENhcnJvCnsKICAgcHJpdmF0ZSBTdHJpbmcgbm9tZTsKICAgcHJpdmF0ZSBpbnQgcG9ydGFzOwogICBwcml2YXRlIFN0cmluZyBjb3I7CiAgIHByaXZhdGUgaW50IGttOwoKICAgQ2Fycm8gKFN0cmluZyBub21lLCBpbnQgcG9ydGFzLCBTdHJpbmcgY29yLCBpbnQga20pCiAgIHsKICAgICAgdGhpcy5ub21lICAgPSBub21lOwogICAgICB0aGlzLnBvcnRhcyA9IHBvcnRhczsKICAgICAgdGhpcy5jb3IgICAgPSBjb3I7CiAgICAgIHRoaXMua20gICAgID0ga207CiAgIH0KICAgcHVibGljIFN0cmluZyBnZXROb21lICgpIHsgcmV0dXJuIG5vbWU7ICAgfQogICBwdWJsaWMgaW50IGdldFBvcnRhcyAgKCkgeyByZXR1cm4gcG9ydGFzOyB9CiAgIHB1YmxpYyBTdHJpbmcgZ2V0Q29yICAoKSB7IH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