4 Introducing Classes
4 Introducing Classes
What is an Object?
• It is called immediately after the object is created but before the new
operator completes.
type of a class
• When the class has no constructor, the default constructor
class Box
{
double width;
double height;
double depth;
Box()
{
System.out.println("Constructing Box");
width = 10; height = 10; depth = 10;
}
double volume()
{
return width * height * depth;
}
}
Parameterized Constructor
class Box {
double width;
double height;
double depth;
Box(double w, double h, double d) {
width = w; height = h; depth = d;
}
double volume()
{ return width * height * depth;
}
}
Methods