Java Essential Basics (1)

Source: Internet
Author: User

1. A class is an abstract concept in which an object is a concrete representation of a class and is a
The concept of the body. There is a class first and then the object is generated by the class. Object Also
Called an instance (Instance).
2. The class consists of two parts: attributes and methods. Properties are generally represented by nouns,
Methods are generally represented by verbs.
3. If multiple classes are defined in a Java source file, these classesup to only
can have a class that is public, in other words, multiple classes of definitions can be
is public.
4. When passing the parameter of a method in Java, regardless of whether the native data class is passed
or reference type, the parameter is passed uniformly as a pass value (pass by value).
There is no concept of pass by reference in Java.
5.Method overloads (Overload). Indicates that two or more methods have the same name, but the
Different method parameters. The method parameter has two layers meaning: 1) The number of parameters is different.
2) parameter types are different. Note: The return value of the method does not have any shadow on the overload
Ring.
6.Constructor method overloading: Just look at the parameters. If you want to be in a construction method
Call another constructor method, which can be called using the This () method, this ()
The parameters in parentheses represent the parameters of the target construction method. This () must be used as a construction
The first statement of the method, in other words, this () cannot be
The code for the line.
7.Inheritance (inheritence): Java is single-inheritance, meaning that a class can only be derived from the
Another class inherits (the inherited class is called the parent class, base class, and the following
The inherited class is called a subclass), and inheritance in Java uses the extends keyword.
8.When a subclass object is generated, Java defaults to calling the parent class's non-parametric construct first
method, and then executes the construction method to generate the object of the parent class. Next, then
To invoke the constructor of the subclass to generate the object of the subclass. "To create a subclass of
Object, you first need to generate the object of the parent class, there is no child class without the parent class object
Object. For example: Without a father, there is no child ".
9.Super Keyword: Super represents a reference to a parent class object.
.If a subclass uses super () to explicitly call a constructor of a parent class, the
Execution will look for the construction method corresponding to super () and will not go
Look for a constructor that has no arguments for the parent class. As with this, super must also
To execute a statement as the first execution of a method, there can be no other executable
Statement.
11.3 points on inheritance:
a) There is a parent class, and subclasses have
b) No parent class, subclasses can increase
c) The parent class has, subclasses can change
12. Considerations Regarding Inheritance
a) The construction method cannot be inherited
b) Methods and properties can be inherited
c) The constructor method of the subclass implicitly calls the parent class's constructor without arguments
D) When the parent class does not have a constructor method with no arguments, the subclass needs to use Super to display
To invoke the constructor of the parent class, Super refers to a reference to the parent class
e) The Super keyword must be the first line statement in the constructor method.
13. Method override (Override): Also called overwrite, the subclass and the method of the parent class return
Type, the method name is the same as the parameter, so we say that the child class and the parent
The methods of the class form an overriding relationship.
14. Method overrides relationship to method overloads: Overloads occur inside the same class
Two or more methods. Overrides occur between the parent class and the child class.
15. When the two methods form a rewrite relationship, you can pass in the subclass method
The Super.run () Form invokes the run () method of the parent class, where Super.run () does not have to be placed
In the first line of the statement, so the parent class object is now constructed, calling the parent
The run () method of the class or the run () method that calls the subclass first is based on the logic of the program
Decision-making.
16. When defining a class, if the parent class of the class is not explicitly specified, the
The class is inherited from the Java.lang.Object class (a class provided by the JDK, Object
Class is the direct or indirect parent class for all classes in Java.
.Polymorphism (polymorphism): We say that the subclass is the parent class (roses are flowers, men
Man is human), so polymorphism means: a reference to a parent type can point to a subclass
The object.

Java Essential Basics (1)

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.