Java Reuse class Knowledge

Source: Internet
Author: User
Tags export class

Java Inheritance extends keyword

Extends keyword is used,
Subclasses and parent classes can all contain the main (string[] args) function. When calling the parent class Main in a subclass, pass the parameter args, such as Father.main (args).

Parent class All methods must be public, and if no access modifiers are added, the member's default access is package access, which allows only members within the package to access it.

When inheriting, the data member private, method public.

It is possible to use the method defined in the base class and modify it, and the Super keyword denotes the meaning of the superclass. Super.fun () means that the base class fun () is called to avoid recursion in the subclass.

When inheriting, subclasses can add new methods.
Subclasses are available for all overloaded methods of the parent class, even if the subclass introduces a new overloaded method. Overwriting a method with the same name using exactly the same signature and return type as the base class is an extremely common thing.
Java joins @overvide annotations. When you want to overwrite a method, you can choose to add this annotation, and the compiler will make an error if you accidentally reload it instead of overriding it.

The call to the base class constructor must be the first thing to do in the Export class Builder (otherwise the compiler will error).


Why don't you need to extends the keyword when acting? An agent is a middle doctrine of combination and inheritance.
A combination is a method that uses a class to inherit a method that overloads a class. A combination is a common reuse of an existing type as part of the underlying implementation of the new type, and the inheritance is reused as an interface.
The keyword try indicates that the following block (the range enclosed in a set of curly braces) is a so-called protected area, meaning that it needs to be handled specially. The code in the finally clause behind the protected area is always executed.

"Knock on the blackboard!" "Tips: When it comes to garbage collection, you need to think twice carefully. The garbage collector may never be called, and even if it is called, it may be able to reclaim objects in whatever order it wants. The best way is not to rely on the garbage collector to do anything except memory. If you need to clean up, you'd better take a kiss. "Knock on the blackboard!!!" 】


Protected, as far as the user is concerned, is private, but is accessible to any export class that inherits from this class or any other class that is in the same package. "Provide in-package access"


Up and down transformation (skip)

Final keyword: A compile-time variable that never changes, a value that is initialized at run time, and does not want it to be changed.
A domain that is both static and final occupies only a certain amount of storage space that cannot be changed. Define static to emphasize only one copy, define final, description is a constant.
For basic types, final makes the values constant, and for object references, final makes the reference constant. Once a reference is initialized to an object, it can no longer be changed to point to another object. (The object itself can be modified).
Blank final is allowed, that is, uninitialized. However, it must be initialized before it is used.
Allowing a parameter to be declared as final in a parameter list means that the object pointed to by the parameter reference cannot be changed in the method.
Final method: ① locks the method in case any inheriting class modifies its meaning, leaving the method behavior intact and not overwritten. ② efficiency.
The final class, which does not allow inheriting classes.

Java Reuse class Knowledge

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.