Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setters-getters 3 classes  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this is a basic question but I really struggle with this

First class:



Second Class:


Third class:



RESULT: 0

I know I make a new object in class A thats why the sysout returns 0. How can I make it so that I GET the value 2 instead of null in class A, and that I'm able to SET things in class B. So I stay at the same object so to say.

I just want to be able to SET things in class B and GET that same value from the setter-getter-class-C, in class A. Please help

Thanks in advance, Jimme
 
author
Marshal
Posts: 23435
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Based on the code you posted, class A should not compile.

Henry
 
Marshal
Posts: 58319
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Henry Wong wrote:. . . class A should not compile.  . . .

The solution is to create an instance method which you can refer to b from.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!