Java notes--finalize, static, abstract, final, this keyword __java

Source: Internet
Author: User
Tags define abstract throwable
1, the life cycle of the object (1) finalize package cn.sdut;
 public class AA {int x=100;
 
 int y=100;
  Public AA () {x=10;
 y=20;
  public AA (int x, int y) {super ();
  this.x = x;
 This.y = y;  
  @Override protected void Finalize () throws Throwable {System.out.println ("AA finalize ...");
 Super.finalize ();
 public void mm () {System.out.println (x+ "= =" +y);
  public static void Main (string[] args) {AA aa=new aa ();
  AA.MM ();
  
  ... aa=null, and the other is the same.
 System.GC ();

}//(2) static package cn.sdut;
 public class AA {static{//Static code block a program in which a static block of code executes the first System.out.println ("Static Block ...");  static int x=100;
 
 Class variable, static variable int y=100;
 Public AA () {y=20;
  public AA (int x, int y) {super ();
  this.x = x;
 This.y = y;  
  @Override protected void Finalize () throws Throwable {System.out.println ("AA finalize ...");
 Super.finalize (); public static void mm ()//class method, static method {System.out.println (x+ "=");
     public static void Main (string[] args) {AA aa=new aa ();
     System.out.println (aa.x);
     x+=20;
     AA bb=new AA ();
     System.out.println (aa.x);
     System.out.println (aa.x);
 AA.MM ();

}//2, Abstract//(1) Abstraction classes cannot be instantiated, (2) Abstract classes can define abstract methods or Non-abstract methods, and (3) classes that contain abstract methods must be abstract classes.

Package Cn.sdut;
 Public abstract class AA {static{System.out.println ("Static Block ...");
  static int x=100;
 
 int y=100;
 Public AA () {y=20;
  public AA (int x, int y) {super ();
  this.x = x;
 This.y = y;  
  @Override protected void Finalize () throws Throwable {System.out.println ("AA finalize ...");
 Super.finalize ();
 public abstract void mm ();
 
 public void mm2 () {};

public static void Main (string[] args {}} 3, final modifier variable, only 1 times assigned; Cosmetic method, subclass cannot override (overwrite) method.

Package Cn.sdut;
 public class AA {final int x;
 
 int y=100;
  Public AA () {x=20;
 y=20;
  public AA (int x, int y) {super ();
  this.x = x;
 This.y = y; Public final VOID mm2 () {};
  
 public static void Main (string[] args) {final int a=10;

} 4, this package cn.sdut;
 public class AA {final int x;
 int y=100;
 
 int z; 
  Public AA () {this (20,20);  
 z=10;
  public AA (int x, int y) {this.x = x;
 This.y = y;
 public void mm2 () {System.out.println (this.x+ "= =" +this.y);
 
 };
 public void Mm3 () {this.mm2 ();
 
 };

 public static void Main (string[] args) {}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.