• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling method from another class  RSS feed

 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to call a method from Video class and its not able to be found. I want to call printTitle from Video class from the method printMovies in my CustomerList class. I thought that as long as I added this ===> Video video = new Video(); to my CustomerList class I would just have to write the code like this temp.video.printTitle(); to make everything visible but I get a cannot find symbol error pointing to video as not found.
 
Todd Buell
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the method of Video declared with appropriate accessibility to be visible by the Customer class? That is, is the method declaration as follows

 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what the method looks like in the video class

 
Todd Buell
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, and the attribute Customer.video is public as well? Because the line you're trying to call requires you have visibility of the attribute of Customer called "video". Sorry I hurried earlier and missed that part as well.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is usually best to give fields private access and permit access via suitable getXXX methods.
Your methods which search the List should not be here; they should be in the list class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!