I have found many examples of creating classes, but how do you call the classes into you code? Example one main class that references multiple classes to build it. I am new to Java and OO. I have done some programming in C++ and Visual Basic
Calling classes in the sense, creating instances of the classes. You need to import the class and create the instances.
You need not to import java.lang.String and java.lang.Integer because java.lang is automatically imported to your app.
You need to do some programming in Java. Things will be more clear then.
Thanks and Regards,
Say you create a simple class called appropriately "SimpleClass" that has one class variable, a string called "myString", and has one method, "callThisClass()", and has one constructor that allows you to initialize the string. You would create the class like so:
To use this class in a separate class you first declare an object of the class:
Before you can use this object however you must construct it. This allocates memory for the object, its variables and its methods.
Now you can use the object:
You can also compress the declaration and instantiation into one step: