The more confusing points of knowledge in Java

Source: Internet
Author: User

1. equals () and = = Operators

-Equals is a method, and = = is an operator (or, of course, a generalized method, or ultimately a calling method).

-Equals () is inherited from the object class, in object where equals is the = = operator that is called directly.

-in Equals, how to compare, you can define yourself, and the = = operator is directly compared to the variables directly stored in the value.

-For 8 basic types, variables are stored in values, so the = = operator compares their values (different base types can also be compared, such as int and char).

-For an object, a variable holds a reference to the object, such as String str = new String ("Roger"); STR stores the address of the object. Therefore, different objects, even if their values are the same, are not necessarily the same.

2. Abstract class

-classes that contain abstract methods, so to understand abstract classes, first understand the abstract methods

-Abstract method

-No specific implementation, must be modified with an abstract

-Must be public, because such inheritance and implementation must be allowed. (If private, you cannot inherit from the Quilt class.) Default is Public

-Abstract class

-Cannot define the object (because there is a broken method, even if it is defined as a disabled object, useless)

-If the subclass does not implement all of its abstract methods, the subclass is also an abstract class.

3. Interface

-the interface refers to a method or function that is called by others. So it can be seen as an abstraction of behavior.

-Can contain variables and methods

-Variable: Implicitly specified as public static final. In general, variables are not defined in the interface.

-method: Implicitly specified as public abstract.

-All methods in an interface must be abstract methods (abstract classes can have non-abstract methods.)

-cannot contain static code blocks and static methods (abstract classes can have).

4. Interface and abstract class comparison

-syntactically: can be differentiated by definition

-Design

-Abstract classes are abstractions of a class of things, that is, abstractions of classes. And an interface is an abstraction of behavior.

-Interfaces are the norm for behavior, and abstract classes regulate behavior and attribute.

The more confusing points of knowledge in Java

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.