Unlike other programming languages like C++, it is not sufficient to declare a variable to have an actual object assigned to it:
Display dis; // dis == null
You need to instantiate an object with
dis = new Display(); // dis now contains a reference to a new Display instance
You can declare a variable and assign a reference to a new instance at the same time, if you like:
Display dis = new Display();
(Note: in Java it is customary to start class names with an uppercase letter)
0
solved what’s the difference between these 2 ways of declaring objects in java?