G
Gleys
I have following question:
I must create a class with the properties: color, width, length,
weight;
height.
So, I create a new class BOX and define the properties:
public class Box
{
public String color;
public int width;
public int length;
public int height;
public int weight;
}
And now I must create the get method and the set method. But I don't
know
for what these methods are and how I create it. And at the end I must
create
a clear() method which will initialize the properties to 0 or empty.
My solution:
public class Box
{
public String color;
public int width;
public int length;
public int height;
public int weight;
public Box ()
{
this.color = "BLUE";
this.width = 5;
this.length = 2;
this.height = 3;
this.weight = 4;
}
public static void main (String[] args)
{
Box Box1 = new Box ();
System.out.println (Box1.color);
System.out.println (Box1.width);
System.out.println (Box1.length);
System.out.println (Box1.height);
System.out.println (Box1.weight);
}
public void Clear ()
{
Clear ();
}
}
Is the get and the set method correct or how I must do it? And for
what are this methods exactly?
I must create a class with the properties: color, width, length,
weight;
height.
So, I create a new class BOX and define the properties:
public class Box
{
public String color;
public int width;
public int length;
public int height;
public int weight;
}
And now I must create the get method and the set method. But I don't
know
for what these methods are and how I create it. And at the end I must
create
a clear() method which will initialize the properties to 0 or empty.
My solution:
public class Box
{
public String color;
public int width;
public int length;
public int height;
public int weight;
public Box ()
{
this.color = "BLUE";
this.width = 5;
this.length = 2;
this.height = 3;
this.weight = 4;
}
public static void main (String[] args)
{
Box Box1 = new Box ();
System.out.println (Box1.color);
System.out.println (Box1.width);
System.out.println (Box1.length);
System.out.println (Box1.height);
System.out.println (Box1.weight);
}
public void Clear ()
{
Clear ();
}
}
Is the get and the set method correct or how I must do it? And for
what are this methods exactly?