Java Oops Ch3 This Finalize Gc

this Keyword

class Rectangle
{
   double width;
   double height;
  Rectangle(double width, double height)
  {
    width=width;
    height=width;
  }
  double perimeter()
  {
    double p= 2*(width+height);
    return p;
  }
 }
 class Main
 {
 public static void main(String args[])
 {
   Rectangle rec1=new Rectangle(10,20);
   
   double vol;
   
    vol=rec1.width * rec1.height; 
   System.out.println("Rectangle 1 area:  "+vol);
   System.out.println("Rectangle 1 perimeter method:  "+rec1.perimeter());
  
  
      }
 }

Result:

Rectangle 1 area: 0.0
Rectangle 1 perimeter method: 0.0

Example with this keyword

class Rectangle
{
   double width;
   double height;
  Rectangle(double width, double height)
  {
    this.width=width;
    this.height=width;
  }
  double perimeter()
  {
    double p= 2*(width+height);
    return p;
  }
 }
 class Main
 {
 public static void main(String args[])
 {
   Rectangle rec1=new Rectangle(10,20);
   
   double vol;
   
    vol=rec1.width * rec1.height; 
   System.out.println("Rectangle 1 area:  "+vol);
   System.out.println("Rectangle 1 perimeter method:  "+rec1.perimeter());
  
  
      }
 }

Result:

Rectangle 1 area: 100.0
Rectangle 1 perimeter method: 40.0

Garbage Collection

protected void finalize( )
{
// finalization code here
}