Java BASICS (10) Object-oriented (5) and java basics object-oriented
Here are some of the knowledge points and code I summarized in my previous class. Most of the notes I think are very good and classic, sincerely hope that these will help those who want to learn!
It is inconvenient to upload code by module. There are also many things, and they are also clear! If you need it, you can leave your email in the comments. I will certainly send it to you for free! Thank you for making progress on this platform !! Remember that programmers are selfless !!!
Also very welcome to my blog to watch blog address: http://www.cnblogs.com/duscl/
/* 1: form parameter and return value (understanding) (1) form parameter: Class Name: the object abstract class name of the class is required: The Interface Name of the subclass object of the class is required: required implementation class object of this interface (2) Return Value Type: Class Name: returned Class Object abstract class name: returned class subclass object interface Name: the returned result is the implementation class object of this interface (3) chained programming object. method 1 (). method 2 ()....... method n (): in fact, an object should be generated after method 1 () is called, and an object should be returned after method 2 () is called. After method n () is called, it may be an object or an object. 2: Package (understanding) (1) is actually A folder (2) Role: a: differentiate classes with the same name B: Classify and manage classes A: divide the class by function B: the package name is defined according to the module (3) package. Multi-level package is used. separated. (4) Note: (GRASP) A: the package statement must be the first valid statement in the file. B: In A java file, only one package is allowed. C: If no package exists, by default, there is no package name (5) Compiling and running with A package. A: manual B: Automatic (master) javac-d. helloWorld. java 3: importing a package (master) (1) It is very troublesome to use a class with a package multiple times. At this time, Java provides a keyword import. (2) Format: import package name... class Name; another type: import package name... *; (not recommended) (3) package, import, class ordered package> import> class 4: Permission modifier (master) (1) permission modifier this class is the same package, different packages, sub-classes, different packages, irrelevant classes, private Y default Y protected Y public Y (2) the four permission modifiers can only appear at any time. Public class Demo {} 5: Common modifiers (comprehension) (1) category: Permission modifier: private, default, protected, public status modifier: static, final abstract modifier: abstract (2) common classes and their composition modifier classes: Default, public, final, abstract commonly used: public member variables: private, default, protected, public, static, final commonly used: private constructor: private, default, protected, public commonly used: public Member method: private, default, protected, public, static, final, abstract commonly used: public (3) also common: public static final int X = 10; public static void sho W () {} public final void show () {} public abstract void show (); 6: internal class (understanding) (1) define the class inside another class, this class is called an internal class. For example, Class B is defined in Class A, and Class B is called an internal class. (2) internal class access rule A: You can directly access members of the external class, including private B: The External class must create an object to access the internal class members (3) classification of internal Classes A: Member internal class B: Local internal class (4) member Internal Class A: private for data security B: static for ease of access, the internal class of the member is not static: External class name. internal class name object name = new external class name. new internal class name (); member internal class is static: External class name. internal class name object name = new external class name. internal class Name (); (5) members internal class interview questions (blank) 30, 20, 10 class Outer {public int num = 10; class Inner {public int num = 20; public viod show () {int num = 30; System. out. println (num); System. out. println (this. n Um); System. out. println (Outer. this. num) ;}}( 6) Local internal class A: Local internal class access local variables must be modified with final. B: Why? Because the local variables disappear after use, and the heap memory data does not disappear immediately. Therefore, the heap memory still uses this variable, and the change volume is no longer available. To make the value still exist, add final. Through the decompilation tool, we can see that after final is added, the heap memory directly stores the value rather than the variable name. (7) Anonymous internal class (master) A: simplified form of local internal class B: premise there is A class or interface C: Format: new Class Name or Interface Name () {rewrite method;} D: essence: it is actually an anonymous object that inherits this class or implements the sub-class of the interface (8) the anonymous internal class is used in development. During development, we will see the abstract class, or the interface is used as a parameter. At this time, we know that what we actually need is a subclass object. If this method is called only once, the format of the anonymous internal class can be simplified. Interface Person {public abstract void study ();} class PersonDemo {public void method (Person p) {p. study () ;}} class PersonTest {public static void main (String [] args) {PersonDemo pd = new PersonDemo (); pd. method (new Person () {public void study () {System. out. println ("good study, every day") ;}}}( 9) Anonymous internal class interview questions (complete the Code) interface Inter {void show ();} class Outer {// complete the code public static Inter method () {return new Inter () {public void show () {System. out. println ("HelloWorld") ;};}} class OuterDemo {public static void main (String [] args) {Outer. method (). show (); // "HelloWorld "}}*\