??????????:
????1.?????
????2.????
????1.?????
????????????Java???????????????..?????????????????????????????????????????????????????.???????????????????????.
????i.????????????.
?????????????£?????????????????.
?????????????????????????????????????????????????????????????.???????????????????????????????????????????????????????????????????????????????????.?????????????????????.????????????????????????????????????????????????????????????????????????(??????????).
class Darker{
private String darker;
public Darker() {
// TODO Auto-generated constructor stub
System.out.println("Default Constructor: "+darker);
}
public Darker(String darker){
this.darker = darker;
System.out.println("Overload Constructor: "+darker);
}
}
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Darker darker = new Darker();
Darker darker2 = new Darker("darker");
}
}
????????????????????.????????????ò??????????????г????.???????????.Java?????????????????????????????????????????????????????????????????????????????????.???????????????????????ò?????????.?????????????????????.
????ii.????????.
???????????????????ι??????????????????????????.??????????????ж??????????????????????????????????????????????????.???????.??????д???class????????????д???????????????????????????????????.
class Darker{
public String getDarker() {
return darker;
}
public void setDarker(String darker) {
this.darker = darker;
}
private String darker;
}
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Darker darker = new Darker();
darker.setDarker("darker");
System.out.println(darker.getDarker());
}
}
/**
*OutPut
*darker
*/
??????????????????????????????????????????????????????????κ??????.?????????????????????????????????.?????????????????..
package com.thinking.in.java;
class Darker{
private String darker;
public Darker(String darker){
this.darker = darker;
}
//    public Darker(){
//
//    }
public String getDarker() {
return darker;
}
public void setDarker(String darker) {
this.darker = darker;
}
}
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Darker darker = new Darker();
darker.setDarker("darker");
System.out.println(darker.getDarker());
}
}
?????????????????????????????????????????вι?????.??????????????????壬???????????????ι?????????????????.Darker darker = new Darker(); ??仰????????????.?????? The constructor Darker() is undefined .??????????ι???????ж???.??????????????????????????Java?????.?????????????д?κ???????????????Java?????????????????????????????????????????????.?????????????????????????(???:?вι?????).???Java??????:?????????????????????????????????????????.?????????????????.????Java??????????????????????.?????????вΣ????????????????????????????????? Darker darker = new Darker()??仰?????????.