Java Basic Knowledge Collation:

Source: Internet
Author: User

One, inheritance in Java:

1. Final keywords (final, immutable immutable, can modify classes, methods, variables, etc.):

If the final modifier class, this class can not be inherited;

If the method is modified, this method can not cover (rewrite) the quilt class;

If the property is decorated, the properties of the class are not automatically initialized.

The final modified variable can only be assigned once. And at the time of declaration, you have to assign a value, which can be called a constant. Can not be assigned anywhere else. (Will be error)

2. Super in Java: Typically used inside an object, representing the parent class object.

Calling method: Super. Parent class method or property.

The method or property of the parent class is called through super in the subclass.

If the constructor of the child class does not show the constructor method that calls the parent class, and the parent class has no argument constructor, the compilation error occurs.

3. Object in Java:

The object class is an ancestor class in Java.

1), toString () method; The object returned is hash code.

2), Equals () method: Compares whether the object's reference only wants the same memory address. When you compare two objects in general, the comparison values are equal and therefore overridden.

Two, polymorphic in Java:

1. Polymorphism is the multiple morphology of the object;

References to the parent class can point to objects of this class;

A reference to the parent class can point to the object of the subclass;

2. Type conversions in Java:

1), upward type conversion;---> No risk.

2), down type conversion;---> Risk problems can be resolved using the instanceof keyword.

3. Abstract class:

Abstract classes focus only on the methods that subclasses must have, and two do not care about the implementation of the method.

4. Interfaces in Java:

A class is a concrete implementation body, and an interface defines a specification that a batch of classes must follow, with the pretext of not caring for the internal data of those classes. Nor do you care about the implementation details of the methods in these classes. He only cares that some methods must be provided in these classes. is used to constrain the class. Define with interface keyword

Interfaces are used only for inheritance. Therefore, the public type (almost). An interface can inherit multiple, but the class is single-inheritance.

Basic syntax for the interface:

"Modifier" Interface Interface Name "extends parent interface 1, parent interface 2 ... 】

{

0 to more constant definitions ...

0 to multiple abstract method definitions ...

}

Properties in the interface

is a constant, the cornerstone is not added when defined:

public static final modifier, the system is also automatically added.

Method in the interface:

The methods in the interface can only be abstract, always used, and are added automatically even when the public abstract modifier is not added to the definition.

A class can implement one or more interfaces.

5. Use the interface through anonymous inner class methods:

//implementing an interface using an anonymous inner classIplaygame IP3 =NewIplaygame () {@Override Public voidPlayGame () {//TODO auto-generated Method StubSystem.out.println ("Implementing an interface using anonymous internal classes");        }                    };                Ip3.playgame (); NewIplaygame () {@Override Public voidPlayGame () {//TODO auto-generated Method StubSYSTEM.OUT.PRINTLN ("Implementing interface 2222 using anonymous internal classes");    }}.playgame (); }

6. UML: Standard Modeling Language (Unified Modeling Language).

1), use case diagram:

2), Sequence diagram:

3), Class diagram:

   

UML Diagram Authoring tool download path Rational Rose:http: // www.uml.org.cn/RequirementProject/200604043.htm visio:http: // www.microsoft.com/china/office/xp/visio/default.asp powerdesignerhttp: // www.uml.org.cn/UMLTools/powerDesigner/powerDesign ...

Java Basic Knowledge Collation:

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.