This link has been bookmarked by 6 people . It was first bookmarked on 18 Dec 2007, by Reder Tseng.
-
26 Aug 09
Lance PedersenWednesday August 26
-
we can add a statement within the
Rectangleclass that prints thewidthandheight: -
within the
Rectangleclass -
prints the
widthandheight -
Code that is outside the object's class must use an object reference or expression, followed by the dot (.) operator, followed by a simple field name, as in:
objectReference.fieldName
-
the code in the CreateObjectDemo class is outside the code for the Rectangle class. So to refer to the origin, width, and height fields within the Rectangle object named rectOne, the CreateObjectDemo class must use the names rectOne.origin, rectOne.width, and rectOne.height, respectively
-
Attempting to use the simple names width and height from the code in the CreateObjectDemo class doesn't make sense — those fields exist only within an object — and results in a compiler error.
-
Recall that the new operator returns a reference to an object. So you could use the value returned from new to access a new object's fields:
int height = new Rectangle().height;
-
essence, the statement calculates the default height of a Rectangle.
-
Note that after this statement has been executed, the program no longer has a reference to the created Rectangle, because the program never stored the reference anywhere. The object is unreferenced, and its resources are free to be recycled by the Java Virtual Machine.
-
Here's the CreateObjectDemo code that invokes these two methods:
System.out.println("Area of rectOne: " + rectOne.getArea()); ... rectTwo.move(40, 72); -
The Java runtime environment deletes objects when it determines that they are no longer being used. This process is called garbage collection
-
References that are held in a variable are usually dropped when the variable goes out of scope. Or, you can explicitly drop an object reference by setting the variable to the special value null.
-
-
21 Mar 09
-
objectReference.fieldName
-
The object is unreferenced, and its resources are free to be recycled by the Java Virtual Machine.
-
The expression new Rectangle(100, 50) returns an object reference that refers to a Rectangle object.
-
The Java runtime environment deletes objects when it determines that they are no longer being used. This process is called garbage collection
-
References that are held in a variable are usually dropped when the variable goes out of scope. Or, you can explicitly drop an object reference by setting the variable to the special value null. Remember that a program can have multiple references to the same object; all references to an object must be dropped before the object is eligible for garbage collection.
-
An object is eligible for garbage collection when there are no more references to that object
-
-
12 Sep 08
-
Note that after this statement has been executed, the program no longer has a reference to the created Rectangle, because the program never stored the reference anywhere. The object is unreferenced, and its resources are free to be recycled by the Java Virtual Machine.
-
An object is eligible for garbage collection when there are no more references to that object. References that are held in a variable are usually dropped when the variable goes out of scope. Or, you can explicitly drop an object reference by setting the variable to the special value null. Remember that a program can have multiple references to the same object; all references to an object must be dropped before the object is eligible for garbage collection.
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.