[Java] Classes and objects

Source: Internet
Author: User

1. Inner class

eg

public class example{

public static void Main (string[] args) {

FirstClass fc = new FirstClass ();

Firstclass.secondclass sc = fc.new secondclass ();

Sc.out (1);

}

}

Class firstclass{

Class secondclass{

public void out (int a) {

System.out.println (a+=3);

}

}

}

2. Construction method

The constructor method name and class name are exactly the same

The constructor does not return a value, not even void, which is different from other methods

The construction method does not appear explicitly, and it is implicitly present. If we do not define a constructor method in the class, the system generates a default, parameterless construction method for use

Construction methods must be called when generating objects with a class

In the constructor method, the default is to use the form of no parameters. If only a parameter is in the form, the default parameterless construction method is not generated. It is also important to pay attention to the value of the argument when the build object calls the constructor method

eg

public class example{

public static void Main (string[] args) {

ABC A = new ABC (); There's a problem here, you can't create an object

}

}

Class abc{

Public ABC (int i, int j) {

System.out.println (I+J);

}

}

[Java] 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.