What does this variable statement mean?

0

This is a doubt that I have been having for a long time, I have been programming for 1 year in Java, but I still do not have the following clear. Suppose I have 2 simple classes

       public class Automovil{
    String patente;
    String modelo;
    int capEstanque;
}

And the other one

Public class Menu{
Automovil auto;
}

I know that to instantiate objects, the = new class () is used, but in this case, in the Menu class, if I leave it as such, that variable% co_of% that it can do? Can you save data? or is it useless?

    
asked by Christian 03.08.2018 в 07:04
source

2 answers

0

The automobile class is an object that encapsulates information related to vehicles, you declare it as an attribute of the Menu class, if it can store information but you will have to assign a value to the attributes of that object, either in the constructor of the class Menu, when initializing it, or in one of the methods of the Menu class itself.

    
answered by 03.08.2018 в 08:24
0

The variable Auto as the.you are only being referenced, but still has no value. You can assign it later in your program but you must instantiate it first having its constructor

// Code

Automovil auto;  //Así sola no hace nada

// Code

auto=new Automovil(valor1,valor2,...); //Ya tiene un valor y la puedes ocupar 
    
answered by 03.08.2018 в 08:50