4 Java Class Fundamentals
4 Java Class Fundamentals
fundamentals
Mr. M.R.
Solanki
Sr. Lecturer, Information Technology,
[email protected]
SBMP
Learning Outcomes
class Box
{
double width;
double height;
double depth;
}
Instantiating an object
in Java
Creating Objects
Obtaining objects of a class is a two-step process:
1. Declare a variable of the class type i.e.
reference
This variable does not define an object.
It is simply a variable that can refer to an
object
We can not apply mathematical operators
i.e. + and – on reference (as allowed in case of
pointer in C/C++)
We can assign one reference to other
reference variable
RAM
Creating Objects
declaration
Variables
We can assign one reference to other reference as
below:
“
problems:
“
Write the previous program by taking user input
from key board using Scanner class.
Introducing Constructor
in Java
Introducing Constructors