java-Basic articles (classes and objects)

Source: Internet
Author: User

1. How to construct a method: Create a new object using the new+ construction method

When creating objects, execute the construction method

Create object process can directly create simultaneous assignment of initial value

Static variables are used in 2.Java: In order for all members of the class to share a member:

1  Public class helloword{23publicstaticvoid  main (string[] args) { 4     // write code that is equivalent to the main function in C + + 5 }67 }

3.java encapsulation: External programs are not allowed to be accessed directly and accessed in a certain way

Encapsulation method to hide the attribute shadow.

4. Package Pakage:

modifiers accessed in 2.Java:

3.this Keyword: Represents the current object, this. property; this. method

This is used in references to external classes outclass.this.name----to refer to variables in external classes

4.---------------------Inheritance---------------------

Subclasses can use the parent class and can override an unsatisfactory method, but the subclass is consistent with the parent class format, and the algorithm can be modified as described below

At the same time, during the operation of the sub-class, the program executes the construction method of the parent class, and then executes the constructor of the subclass.

Object initialization: If the object values in the parent class are first exported, the same property of the method in the object overrides the object property initialization value

5.final Keywords:

6.super keyword: Super uses the methods and properties of the parent class directly

5 polymorphic ************************************

Inheritance is the basis of polymorphism; //We can only point to subclasses by reference to the parent class, and cannot point to the parent class with the object of the child class

If the subclass has a method that the parent class does not have, the polymorphic error will occur if the unique method in the subclass is called Animal obj2=new Dog ();//The parent class refers to a method of a subclass

Obj2.watchdog ();//watchdog method is not in the parent class, if this is called, it will be an error.

6. Reference type conversions: No risk for up-type conversions, down-type conversions are risky (data overflow occurs)

Type Judging by keyword instanceof

7*********** abstract class: Retouching with the abstract keyword

java-Basic articles (classes and objects)

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.