Java Beginner Notes Summary Day7

Source: Internet
Author: User

eclipse-"Debugger Mode
Role? --"Debugger error (run error)"
Program code can be executed dynamically, and the value of the variable (constant) to the current execution environment can be viewed at execution time.
Debugger Steps to debug
1) Set breakpoints
2) Run the program through Debuubger
3) switch to Debuger platform
4) Debug According to the debugger view

Access modifiers

Role? --"control where resources (classes, properties, methods) can be accessed

4 levels
Access location
A) public (common): 1) in this class 2) same package other Class 3) subclass 4) Other packages other classes
b) protected (protected) 1) in this Class 2) in the same package other Class 3) sub-class
c) Default (Default-no keyword-no write access modifier) 1) in this class 2) same package other classes
d) Private (private) 1) in this class

Application Location
A) class: only use Public,default
b) Methods and properties: 4 levels are available.

Object-oriented--"encapsulation

Concept: assigning multiple data and functions in a business to different classes, managing them through classes, and
Data and functionality (publicly available), putting the user's data and functions out of concern (shielding them).

Benefit----------to facilitate the user to better use the class, prevent misoperation.

Object Oriented--"inheritance"

Inheritance in life: a kind of A is another class B, then a inherits B.
For example: Humans are animals, humans inherit animals, animals are creatures, animals inherit creatures.
People indirectly inherit the creature.
Succession chain: Man-"Animal---" biology.

Java implementation Inheritance-"people Inherit animals"
Syntax: Class person extends animal{}

Benefit-The code (data and functionality) that reuses the parent type (the inheritance chain) in the subtype. Put the universal (data and function)
Defined in the parent type and can be used directly in subtypes.

Watch out.
1) Java class inheritance is a single inheritance, and a class can inherit only one class.
2) class does not show an inherited class, the default Inherits object, so object is the parent type of all classes (reference types)
3) subtypes can use not only the parent class (data and functionality) but also the inheritance chain.
4) Constructors and private resources cannot inherit


Block

Block Classification Syntax position function

Restrict local variable scope in block or method of ordinary block
Object class in the construction block {} class.
Class initialization in static block static{} class

Execution comparison of blocks and methods
1) method can be called by name to execute
2) block without a name, are automatically executed
3) block as little as possible, readability is not high

Construction Block Execution Time---"Every time the object is created

Static block execution actual---"After the Load class executes (only once)
Load class: First use Class (a) to create an object of Class B) use static properties and methods of the Class)

Construction block and constructor selection?
1) must be executed and does not require the initialization of the parameter = = "Building block
2) Other conditions--"constructor"

Procedures for creating objects
1) The class in which the object resides and the class of the inheritance chain have no static initialization and no static initialization.
Static initialization: Performs all static properties and static blocks (from top to bottom) of each class from top to bottom of the inheritance chain

2) Open space to create objects
3) Use the construction block constructor of each class with the object you just created from the inheritance chain up to down
4) Return the address of the object

Summarize
1) First Static, after the member of the
2) Late father class, after sub-category
3) First construct block, rear constructor
4) Subclasses call the null constructor of the parent class by default

Override (Overwrite)

Why demand? There are functions in the parent class that are also in subclasses, but the functionality of the parent class does not meet the requirements, so subtypes can define
The same functionality (the same as the method signature) overrides the parent class for functionality that does not meet the requirements, and masks it.

After overriding: When the subclass executes the overriding method, it calls its own override method.

Overriding syntax requirements (two methods in the parent and subtype types)
1) The signature of the method is the same
2) return value type
A) basic type and void subtype = = Parent Type
b) Reference type subtype <= parent type
3) Access modifiers
Subtype >= Parent Type
4) Throw exception list (say the exception)
Subtype <= Parent Type

overriding point of attention
1) for the member method-cannot be a static method
2) The method of the parent class is private-cannot be overridden

How to check if a subtype's method has been overridden
Add @override--to subtype method if not rewritten, compile error

Java Beginner Notes Summary Day7

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.