One year ago, I wrote the springmvc project directly from python. The boss said don’t read the basics, write the code directly, and check again when you encounter problems. After listening to him, I don’t even know what the jdk is, and I just write it when I get started. I have been from spring for a year. Mvc to spring boot has four or five items in large and small letters, and now you have to look up keywords when you write a hello naked, which is really amazing. So it! Now go through the basics of doubt? Can't be a silly critic anymore! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
What is the construction method?
public class Goucaohanshu{
public Goucaohanshu(){
}
public Goucaohanshu(String a){
System.out.println(a);
}
public Goucaohanshu(String a, String b){
System.out.println(a);
System.out.println(b);
}
public static void main(String[] args){
Goucaohanshu G1 = new Goucaohanshu();
System.out.println("+++++++++++++++++++++++++++++++++++++");
Goucaohanshu G2 = new Goucaohanshu("hello");
System.out.println("+++++++++++++++++++++++++++++++++++++");
Goucaohanshu G3 = new Goucaohanshu("hello","world");
System.out.println("+++++++++++++++++++++++++++++++++++++");
}
}
In fact, if you don’t write a constructor, the compiler will give one by default. A class can have multiple constructors.
关于public protected default private?
Scope | public | protected | default | private |
---|---|---|---|---|
This category | AND | AND | AND | AND |
Same package | AND | AND | AND | N |
Same package sub-category | AND | AND | AND | N |
Different types of buns | AND | The subclass instance can access the protected method inherited from the base class, but not the protected method of the base class instance | N | N |
Different packages | AND | N | N | N |