Java Day 09

Source: Internet
Author: User

Constructor for child parent class
In the constructor of the subclass, the first line has a default implicit statement: Super ()
Instantiation of subclasses: All constructors in a subclass access the constructor of the null argument in the parent class by default.

Why do you want to access the constructor in the parent class when the subclass is instantiated?

Sub-class instantiation details
The constructor shows when initialization is complete
The default initialization of the parent class constructor displays initialization
Person p = new person ();
1. The JVM reads the. class file and loads it into memory
2, heap memory open up space,
3. Default initialization of object properties
4. Call the constructor to initialize
5. In the constructor, call the parent class constructor and initialize
6, the properties of the sub-class display initialization
7. Specific initialization of a child class constructor
8, initialization is complete, assign the value to the reference variable

Final keyword
class method variables
A decorated class cannot be inherited
The modified method can not be overridden
Modified variables can only be assigned a value once the variable name is all uppercase

Abstract class
Abstract method with ";" End

Characteristics
1, the method only declares, does not implement, needs to use the abstract adornment, simultaneously the class also to be the abstract adornment
2, abstract class can not be instantiated.
3. The inherited subclass must override the abstract methods of all the parent classes to be instantiated. No person

Details
1. The abstract class has a constructor, which is used to initialize the subclass object.
2. Abstract classes can not define abstract methods, the purpose is to not let the class do not create objects. Example: The adapter object for AWT is this class
3, abstract keywords can not and which keywords coexist private, static, final
4. The similarities and differences between abstract class and general class are used to describe things;
Different: Describe the whole and incomplete information of things, there is no abstract method, can be instantiated
5, abstract class must be a parent class?
is to require subclasses to overwrite their abstract methods

Interface
The method inside it is all abstract method, the key is interface;
1, common member global constants, abstract methods, have fixed modifiers, do not write automatically add
public static final
public abstract
The members of the interface are public permissions

Implement implements
Interface cannot be instantiated

Multi-Implementation

Details
Avoids the limitations of single inheritance
Multiple inheritance between interfaces, whether the method body is overloaded

Characteristics
Multi-implementation, reduced coupling, functional expansion

The difference between an interface and an abstract class
The same point: both are extracted concepts
Different points:
1, abstract is the inheritance relationship, single inheritance
Interfaces are implementation relationships, multiple implementations
2, abstract class is a relationship
Interface is like a relationship
3. Non-abstract methods can be defined in abstract classes
The methods of the interface are all abstract methods, and there are fixed modifiers

Java Day 09

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.