0

Access problems

So the mission is to access class Book for main (not a problem), then access defined in main variables of the Book in method next() of class Display and use the method in main. Book-Database-Display-Database e g class Book { int pages;} class Database { main { Book b= new Book; b.pages = 42; next(); }} class Display { static int next() { return b.pages++;}} I can willingly tell errors that I had using different options

29th Mar 2017, 8:32 PM
Alex Snaidars
Alex Snaidars - avatar
8 ответов
+ 2
You need to pass the book object in display class. For instance in constructor or use a setter method.
29th Mar 2017, 8:45 PM
Thomas Zenglein
Thomas Zenglein - avatar
+ 1
I have plenty of them passed in main. Variables are assigned to each one. The problem lays in lack of method's access to main. The ideal would be to declare the method in main, but errors tell me that I can't do so.
29th Mar 2017, 8:52 PM
Alex Snaidars
Alex Snaidars - avatar
+ 1
Sorry?
29th Mar 2017, 9:03 PM
Alex Snaidars
Alex Snaidars - avatar
0
Why don't you implement the next method in your Book class non static? Do you really need Display class?
29th Mar 2017, 8:39 PM
Thomas Zenglein
Thomas Zenglein - avatar
0
I have some attributes defined there
29th Mar 2017, 8:42 PM
Alex Snaidars
Alex Snaidars - avatar
0
I think you need a pointer to the current Page. From your code I cannot See.
29th Mar 2017, 9:01 PM
Thomas Zenglein
Thomas Zenglein - avatar
0
I started an example you can find in my stuff.
29th Mar 2017, 9:10 PM
Thomas Zenglein
Thomas Zenglein - avatar
0
Sorry, I'll answer you tommorow. I'm falling asleep. You might give a brief look at the actual code I uploaded.
29th Mar 2017, 9:19 PM
Alex Snaidars
Alex Snaidars - avatar