Java entry (different from C ++)

Source: Internet
Author: User

Java entry (different from C ++)

When I was a beginner in java, I always wanted to compare it with the previous C ++. After reading the MOOC java getting started video, I always thought that in the object-oriented aspect, it has many similarities with C ++. As a result, we learned two differences today. Now we can record it:

1. there are four types of java access modifiers: private default protected public. If no access modifier is written before the member variables or member functions, it is accessible in the same package by default, and others are not allowed.

2. Internal classes are classes that can be defined inside a class or function. Internal classes can access all data of external classes, including private member variables. There are four internal types:Member internal class static internal class method internal class anonymous internal class

Member internal class(1) External classes cannot directly access members of internal classes. You must first define the objects of internal classes and then access their members through objects.

(2) You must create an internal class object through an external Class Object. Outer ou = new Outer () Inner in = ou. new Inner ()

Static internal classPublic static class Inner {} can be directly created by the internal class Object Name = new internal class ()

Internal method classThe class defined in the method can only be used in the method, and the access modifier and static

Anonymous internal classNo name, so it can only be used once, which can be used to simplify the code

 

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.