Skip to content

Instantly share code, notes, and snippets.

@h26k2
Created October 25, 2019 13:19
Show Gist options
  • Save h26k2/8f7d97685bc88091387d7aa5bd43f0c4 to your computer and use it in GitHub Desktop.
Save h26k2/8f7d97685bc88091387d7aa5bd43f0c4 to your computer and use it in GitHub Desktop.
Constructor and destructor
package homework;
public class Homework {
public static void main(String[] args) {
//Ceating Objects
AutoCopy ac = new AutoCopy("h26k2",262);
AutoCopy ac1 = new AutoCopy(ac);
//Performing Actions
System.out.println("============ VALUES FROM FIRST OBJECT =======================");
ac.displayValues();
System.out.println("============ VALUES FROM SECOND OBJECT =======================");
ac1.displayValues();
//Using garbage collector
System.gc();
}
}
class AutoCopy{
private String name;
private int id;
AutoCopy(String n , int i){
this.name = n;
this.id = i;
}
AutoCopy(AutoCopy c){
this.name = c.name;
this.id = c.id;
}
void displayValues(){
System.out.println(" Value of name : " + this.name + "\n Value of id : " + this.id);
}
public void finallize() throws Throwable{
System.out.println("Program Garbage has been successfully deleted! Your memory is boosted");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment