The relationship between class and class java study notes (seven)

The relationship between class and class

A is-a B Generalization (Inherited implemented)
A has B-A comprising (a combination of aggregate association)
A B A use-dependent (dependent) (need-a)

Inheritance is-a

  1. Subclass inherits the parent class, through a keyword extends
  2. Object subclass can call (public protected) properties and methods of the parent class as their use
    2.1 constructor strict sense, it does not subclass inherited
      by default when you just simply call the constructor in subclass called the father constructor
    2.2 blocks in the strict sense do not subclass inherited (subclass name did not call themselves)
      before the block can not be called a subclass of the subclass constructor is executed directly
      default constructor calls the parent class of the parent class automatic execution block before the parent class constructor
  3. Subclasses can add subclasses own unique properties and methods can also add their own unique members (attribute method)
  4. Subclass inherits from the parent class over the method can not meet the needs subclass, can be overridden in a subclass (cover) method of the parent class refers to the content of more
       4.1 regarding method overrides (override) and method overloading (overload )the difference
  5. Each class has inherited class, if you do not write the extends keyword, the default Object inheritance, if you inherit wrote back that extends the parent class
    can be understood as the Object class is very important to any parent of a reference type (direct or indirect successor Object) Object class does not have a parent class
      Object class is very important, he is the father of all reference types, the Object class is not the parent class
      
      method Object class
  6. Java is a single inheritance exists (single inheritance) Each class can have only one inherited class (a class can only be written after the extends keyword)
    can implement multiple inheritance effect by way of follow-up will deliver realize how
  7. Inherited forms of storage in memory
  8. Use of super about this and
    this and super refer to the pronoun is the object instead of
    this substitute is the object of the current execution method is not necessarily the current class of
    super parent class instead of the internal space of the object when the object of the current execution method that
    can call the general properties and general method
    can be placed anywhere on class members (attributes building block approach)
      Note that when you call the general method of calling back and forth to each other (written to compile useful) execution may cause problems (StackOverflowError)
    call constructors the method (first row in the constructor method)
      the this and other super class constructor call can not occur simultaneously in the constructor in the first line
      between the constructor does not call each other back and forth (not easy to use the compiler)

Object class method

hashCode ()    The object address in memory after a calculated integer int
           public Native int hashCode ();
the equals ()      is used to compare the effect of two default content object is Object ==
           == basic types can be compared (comparison value) reference type may be compared (compare address)
           when the equals method of Object class inherited methods defaults comparison address
           if you want to change the rules can be overridden method
           public Boolean equals (Object obj) {
             return (the this == obj);
           }
toString ()     when the object becomes printout string string
             public string toString () {
                return this.getClass () getName () + "@" + Integer.toHexString (this.hashCode ());.
             }
getClass ()     Gets class map corresponding to the object class (reflecting)
the wait ()        thread into the suspend state waiting present method overloading
notify ()      Thread wakes
notifyAll ()      wakes up all
finalize ()      rights protected default modifier is executed and when the object is recovered by GC method
            final finally finalize distinction
            protected void finalize () {
            }
clone ()      rights are protected modifier to clone

Published 30 original articles · won praise 0 · Views 6648

Guess you like

Origin blog.csdn.net/qq_37710756/article/details/103356302