Briefly describe the abstraction and encapsulation, which has some function for you to learn Java. Briefly describe java
As a beginner in Java, you may have some one-sided or even some incorrect understanding of Java. You may wish to watch it here !!!
God knows why I chose to learn programming. I don't like programming. But now that I have learned, I will continue to study hard and share some learning experience here.
Access modifier:
1. Common Access modifiers:
Public
Private
Protect Protection
Public can be used by everyone, private can be used by themselves, protect is a bag.
2. Automatically correct the shortcut key ctrl + 1 (Note: Search for the MyEclipse shortcut key Daquan, you can find all the shortcut keys)
The real usage also requires your own experience in the environment.
3. object-oriented, such:
First set up a Student Class 1:
1 package cn. curry. day01; 2 3 public class Student1 {4 private String name; 5 private int age; 6 public String getName () {7 return name; 8} 9 public void setName (String name) {10 this. name = name; 11} 12 public int getAge () {13 return age; 14} 15 public void setAge (int age) {16 17 if (age <= 16) {18 this. age = age; 19} 20 else {21 this. age = age; 22 System. out. println ("the age cannot be more than 16 years old! "); 23} 24 25} 26 public void studentInfo () 27 {28 if (this. age> 16) {29 return; 30} 31 System. out. println ("Student name" + this. getName () + ", age:" + this. getAge (); 32} 33 34}
Set up a Student Category 2
1 package cn. curry. day01; 2 3 public class Student2 {4 private String name; 5 private int age; 6 private String sex; 7 private String work; 8 public Student2 (String sex, String work) 9 {10 this. setSex (sex); 11 this. setWork (work); 12} 13 public Student2 (String name, int age, String sex, String work) 14 {15 16 this. setName (name); 17 this. setAge (age); 18 this. setSex (sex); 19 this. setWork (work); 20} 21 22 public String getName () {23 return name; 24} 25 public void setName (String name) {26 this. name = name; 27} 28 public int getAge () {29 return age; 30} 31 public void setAge (int age) {32 this. age = age; 33} 34 public String getSex () {35 return sex; 36} 37 public void setSex (String sex) {38 this. sex = sex; 39} 40 public String getWork () {41 return work; 42} 43 public void setWork (String work) {44 this. work = work; 45} 46 public void myself () {47 System. out. println ("My name is" + this. getName () + ", age is" + this. getAge () + ", gender is" + this. getSex () + ", Major" + this. getWork (); 48} 49 50}
These two types only display student information, but some methods are different. Classes are abstract. A class can have n objects, and an object can only come from one class.
4. One-time generation of all fields
The cursor stays behind the last field, then alt + shift + s, then r + alt + a, and then alt + s
5. Quick Method for creating classes ctrl + n
Format the code block ctrl + shift + f
6. Constructor
The method name is the same as the class name. No return value is returned, and no void is returned!
7. Method overloading: in the same class, the method name is the same and the parameter list is different. It is irrelevant to the return value and access modifier! ,
8. static keywords
Modify a class member. All classes share one content.
Static code block
1 package cn. curry. day01; 2 3 public class Dog {4 private String name; 5 private String age; 6 public String getName () {7 return name; 8} 9 public void setName (String name) {10 this. name = name; 11} 12 public String getAge () {13 return age; 14} 15 public void setAge (String age) {16 this. age = age; 17} 18 public static Cat [] cats;
// Static code block 19 static {20 cats = new Cat [2]; 21 System. out. println (); 22 cats [0] = new Cat (); 23 cats [0]. setName ("rhubarb"); 24 cats [1] = new Cat (); 25 cats [1]. setName ("yellow"); 26} 27 28}
9. usage of this
The basic things are all there. Please follow the next blog to expand things in the future!