Java Fundamentals 2

Source: Internet
Author: User

One: Inherit extends

Features: Subclasses inherit all the properties and methods of the parent class (but not the construction method), and can add new properties and methods for themselves. Java only supports single inheritance [a subclass has only one parent class].

Pros: Improve the reusability of your code.

Two: Super keyword

1. The constructor of the calling parent class can be displayed by using the Super keyword in the first line of the constructor method

2. The normal method of calling the parent class is displayed

3 access Modifiers

Used to modify a class, method, member variable:

Public: Publicly, everything is visible

Private: This class is visible

Protected: protected; visible to this class, all subclasses, and this package

Default (no modifier): This package is visible [if the child parent class is not in the same package, the subclass cannot access the members of the default access modifier in the parent class]

4. Method rewriting (overload)

1. Two methods that occur in subclasses and parent classes

With the same method name, argument list, and return value type, the access scope cannot be reduced.

Used when not satisfied with a method in the parent class [for polymorphism]

2. Method overrides and Method overloads

Overloading: Multiple methods in the same class occur, with the same method name, the parameter list must be different

Override: Occurs between child parent classes, same method name, same argument list, same return value type

Java Fundamentals 2

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.