This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > September 2004 > Java creat class with set and get





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Java creat class with set and get
Gleys

2004-09-28, 7:27 am

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?
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews