Java Object-oriented

Source: Internet
Author: User

Java Object-oriented
Object
Everything we can see in our lives is the object of all things we can touch. In the program, all things in life are simulated, everything is object.
As long as the object-property and behavior (method)
Property
What does the object have?
For example: Students have names, school numbers, grades, classes and so on.

Inherited
Create a new class by extending an existing class and inheriting the class's properties and behavior.
The existing class is the parent class (base class, superclass), and the new class is a subclass (derived class).
An object "has a" property, an object that "executes (does)" a behavior.
Using inheritance can not only reuse existing code, avoid code duplication, but also create a program that is easier to maintain and modify.
Using is a relationship to judge inheritance
When using inheritance, you must be able to say that the subclass "is a" parent class.
One class inherits other classes using the Extends keyword
A Java class has only one parent class.
OBJECTJ is the root class of all classes

Method overrides
Subclasses can override methods inherited from a parent class, allowing subclasses to add or to the behavior of methods in the parent class.
Rules
The type of the return value of the method of the subclass, the method name and the formal argument list, must be the same as in the parent class.
The access modifier must be not less than the access modifier in the parent class.
An exception overridden in a subclass cannot throw more exceptions to this parent class.
Determines whether two objects are equal with the Equals () method
If two objects are equal, they must produce the same hash code. Therefore, if you override the Equals () method, you also need to override the Hashcode () method.
Equals () Compares two objects for equality, = = is used to detect whether two references point to the same object.
Two string values do not open up new space, two string values are different to open up new space, new stiring force to open space.
Call the parent class with the keyword super
If the constructor does not use the Super keyword, the compiler automatically adds a parameterless super () to call the parent class constructor.
Final keyword
You can declare the final class (no subclasses) and methods (cannot be overridden).

Java Object-oriented

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.