Java Basic Note 9

Source: Internet
Author: User

Super keyword

Represents the parent class object.
1. You can call the overridden method in the parent class.
2. Also call the constructor method in the parent class. Placed in the first row of the subclass construction method. Cannot appear at the same time as this keyword.

Final keyword

1. Modifier properties. Represents a constant. The amount that cannot be changed. The definitions of constants are all capitalized. Example: publicstatic final int num=20;
2. Modification method. Indicates that the method cannot be overridden by a quilt class.
3. Modifier class. Indicates that the class cannot have subclasses. For example, theString class.

instanceof Keywords

  Application format: Object name instanceof class name returns a boolean type value

Effect: Determines whether an object is an instance of the class.

Abstract class

There is a class in Java that specializes in parent classes.
Classes that use the abstract adornment are abstract classes.

Abstract methods: Methods that use the abstract adornment and do not have a method body. Abstract methods must be placed in an abstract class. Example: Publicabstract void Fun ();

Features of abstract classes and abstract methods:
1. All are decorated with the abstract keyword.
2. There is no method body for abstract methods. {}
3. The abstract method must be placed in an abstract class.
4. An abstract class cannot instantiate an object.
5. An ordinary subclass inherits an abstract class, and the subclass must override all abstract methods in the abstract class.

interfaces (which can be understood as rules or rules)
1. Prior comprehension:
An interface is a special kind of abstract class.
Because all methods in the interface are abstract methods and global constants.
2. Define the interface.

          Interface interface Name {

public static final: Modifier attribute member//global constant

Public Abstract: Modification method//abstract method


These are fixed formats, so you can omit them.

3. Interfaces cannot be instantiated either. The interface can be implemented by the class (keyword implements), and a class can implement multiple interfaces.

4. A class must inherit a parent class and implement multiple interfaces.
    public class class name extends parent class name implements Interface 1, interface 2 ... {


}
5. Interfaces can inherit interfaces. and support multiple inheritance.
    Interface A extends B,c,d ... {

}

Java Basic Note 9

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.