2020 |
07,10 |
class User {
String name ;
User(String name){
this.name = name;
}
//this() とはこのクラスのコンストラクターという意味
//引数がひとつのコンストラクターを読んでくれるので
//this.nameにMeが設定される
User(){
this("Me!");
}
void sayHi(){
System.out.println("hi " + this.name);
}
}
public class MyApp{
public static void main(String[] args){
//Class
User tom;
tom = new User();
System.out.println(tom.name);
tom.sayHi();
}
}
PR
Post your Comment