Object Oriented java- - configuration code block

class Person

{

  private string name;

  private int age;

  /*

  Configuration code block

  Role: to initialize the object

  Objects on the establishment of a run, and takes precedence in the constructor

  And the difference between the constructor:

  Code block is configured to uniformly initialize all objects, while the constructor initializes the object to the corresponding

  Different configurations of the image block of code defines commonalities

  */

  {

    System.out.println("person code run");

  }

  Person()

  {

    System.out.println("person");

  }

}

 

class Persondemo()

{

  Person p1= new Person();

}

Guess you like

Origin www.cnblogs.com/up-day/p/11589523.html