Java Classes:
Use a qualifier, a class keywords, an identifier, and a pair of {}
public class Hello{
public Hello(){
public int myInt;
private float myFloat;
//This is a constructor
}
}
Whenever a class is instantiated, meaning memory is allocated, the constructor is called.
The constructor in Java has the same name as the class, and no return type.
One of the primary uses of a constructor is the initialization of member variables.
Like a C structure, a Class can contain different fields of data.
These fields can be made “public” or “private”
The same as C++, private data members cannot be accessed without using a function.
Typically, the private data members have a “get” function to get the data.
int getData()
And a set function in order to assign the data.
void setData(int myParameter)
Collection Data Types
Java Classes:
Use a qualifier, a class keywords,