java
1public class TestOya extends AppCompatActivity{ 2 3 public String name; 4 public int birthday; 5 public int manpukudo; 6 7 public TestOya(){ 8 this.name = "山田"; 9 this.birthday = 19900101; 10 this.manpukudo = 50; 11 } 12 13 public void eat(){ 14 this.manpukudo += 60; 15 } 16 17}
java
1public class MainActivity extends TestOya { 2 3 4 @Override 5 protected void onCreate(Bundle savedInstanceState) { 6 super.onCreate(savedInstanceState); 7 8 TestOya test = new com.example.macpro_n_goto.test20161113_gamennseni.databases.TestOya(); 9 10 test.eat(); 11 12 System.out.println("名前:" + this.name); 13 System.out.println("生年月日:" + this.birthday); 14 System.out.println("満腹度:" + this.manpukudo); 15 16 System.out.println("名前:" + test.name); 17 System.out.println("生年月日:" + test.birthday); 18 System.out.println("満腹度:" + test.manpukudo); 19 20 System.out.println("Aのオンクリエイトが呼ばれました"); 21 22 setContentView(R.layout.activity_main); 23 } 24}
結果
I/System.out: 名前:山田
I/System.out: 生年月日:19900101
I/System.out: 満腹度:50
I/System.out: 名前:山田
I/System.out: 生年月日:19900101
I/System.out: 満腹度:110
同じフィールドを参照してるのになぜ値が違うのでしょうか?
本当にごっちゃになってきました。
納得できる解説をお願いします!
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/18 17:24
2016/11/18 17:30
2016/11/18 17:32