-1
public class student
{
private String name,int age;
public student()
{
String name = "Dominic";
int age = 10;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public static void main(String[] args)
{
student s= new student();
System.out.println("The name and age of employer is:");
System.out.print(s.getName()+"\tand\t"+s.getAge());
}
}
短い答え...あなたのコンストラクタでは、クラスレベルの変数の代わりに*新しいローカル変数*を初期化しています。あなたは決してクラスレベルのものを設定しません。 – David