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