Today Plant Science:
/ * 2019.08.19 started to learn, to make this shift. * /
1.String class
Examples of: ①String name1 = "John Doe";
②String name2 = new String ( "John Doe");
2. == comparison is a reference, equals comparison is specific content.
String name3 = name2; // pass a reference
name2 == name3 ; ----> true
Example 3. Two of the difference:
① direct assignment: create an object to a String object storage pool, if present, will not be created. (Shared memory)
②new: always create a new object. (New memory zone)
4. immutability string content: only by pointing to a new memory address.
String name = "张" ;
name += "三" ;
The member variables in the heap area, local variables in the stack area.
6. traversal string:
for(int i = 0 ; i < string.length() ; i++) char c = string.charAt(i) ;
7.String class common methods:
①char charAt(int index)
②int length()
③int indexOf()
④String substring(int beginIndex)
⑤String toUpperCase () // transfer of capital; toLowerCase () // small letter
⑥trim () // ignore blank before and after
8. class inheritance: the subclass can inherit attributes and methods of the parent class.
a.Java only supports single inheritance b. private method can not be inherited
Generating a get / set methods: alt + shift + s
Format: sonClass extends FatherClass
As: Dog defined class, the class inherits from the Animal and override methods in parent classes.
super: call the constructor and members of the parent class. Such as: super.funcName ();
Constructor with no arguments constructor with no arguments and subclasses subclass instance objects (new) call the parent class.
Object is a superclass of all objects.