Java Basics:
1: Problems with formal parameters and return values (1) Formal Parameters: Class Name: Object abstract class name required for this class: Subclass object Interface name that requires this class: An implementation class object that requires the interface (2) Return value type: Class Name: Returns the object abstract class name of the class: Returns the Subclass object interface name of the class: an object (3) Chained programming object that returns the implementation class of the interface. Method 1 (). Method 2 () ... Method N (); This usage: In fact, after the invocation of Method 1 (), an object should be returned, and after the call to Method 2 (), an object should be returned. After the method n () call is complete, the object may or might not be an object. 2: Package (1) is actually a folder (2) Role: A: Distinguish the same name of the Class B: Class classification management A: According to the function of B: According to the module (3) package defines the package name; (4) Note: A:package statement must be in the file of the first valid statement B: In a Java file, there can only be one PACKAGEC: if there is no package, the default is the non-packet name (5) with the package compiled and run A: Manual B: Automatic javac-d. HELLOWORLD.JAVA3: Common modifiers (1) Category: Permission modifier: Private, default, protected,public status modifier: Static,final abstract modifier: abstract (2) Common classes and their constituent modifiers: default, Public,final,abstract Common: Public member variables: private, default, Protected,public,static, Final common: Private construction Method: Private, default, Protected,public Common: Public member Method: Private, default, Protected,public,static,final, Abstract Common: Public (3) also more common: public static final int X = 10;public static void Show () {}public final void show () {}public abstract void Show (); 4: Inner Class (1) defines a class inside another class, which is called an inner class. Example: Class B is defined in Class A, and Class B is called an inner class. (2) Access rules for internal classes A: You can access members of external classes directly, including private B: external classes to access internal class members, you must create an object (3) Class A: member Inner Class B: Local inner Class (4) member inner class a:private in order to countThe security b:static in order to access the inner class of the convenience member is not static: the external class name. Internal class Name Object name = new External class name. New inner class name (); The member inner class is static: The outer class name. Internal class Name Object name = new External class name. Internal class name (); r {public int num = 10;class Inner {public int num = 20;public void show () {int num = 30; SYSTEM.OUT.PRINTLN (num); System.out.println (This.num); System.out.println (Outer.this.num);}}} The display result is 30 20 10 (5) Local inner Class A: Local inner class access local variables must be final decorated. B: Why? Because local variables are used to disappear, the heap memory data does not disappear immediately. So, the heap memory is still using the variable, and the variable is gone. In order for the value to exist, the final decoration is added. With the anti-compilation tool we see that, after the final, heap memory is stored directly in the value, not the variable name (6) Anonymous inner Class A: is a simplified form of a local inner class B: If there is a class or interface C: Format: New class name or interface name () {override method;} D: The essence: A subclass that inherits the class or implements an interface anonymous object (7) Anonymous inner class in development use when we are developing, we will see abstract classes, or interfaces as parameters. And this time, we know that what is actually needed is a subclass object. If the method is called only once, we can use the format of the anonymous inner class to simplify
Java Programming Quiz:
There are n individuals in a circle, order automatic arranging. Starting from the first person (from 1 to 3 off), where 3 of the people out of the circle, ask the last left is the number of the first
1 import Java.util.Scanner;2 Public classexample{3 Public Static voidMain (string[] args) {4System. out. Print ("Please enter an integer:");5Scanner scan =NewScanner (System.inch);6 intn =scan.nextint ();7 scan.close ();8 9boolean[] IsIn =NewBoolean[n];Ten for(intI=0; i < isin.length; i++) One { AIsin[i] =true; - } - the intIncount =N; - intCountnum =0; - intindex =0; - while(Incount >1) + { - if(Isin[index]) { +countnum++; A if(Countnum = =3){ atCountnum =0; -Isin[index] =false; -incount--; - } - } -index++; in if(index==N) -index =0; to } + for(intI=0; i<n;i++) - if(Isin[i]) theSystem. out. println ("What's left is:"+ (i+1)); * } $}
Java Learning notes (6)