Westonci.ca is the ultimate Q&A platform, offering detailed and reliable answers from a knowledgeable community. Experience the convenience of getting accurate answers to your questions from a dedicated community of professionals. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

Ben wants to create a Book class that has an instance variable serialNumber. Where should he declare the instance variable

Sagot :

Answer:

within the Book class but needs to also be outside of any methods.

Explanation:

If Ben is creating an entire Book class then the instance variable needs to be within the Book class but needs to also be outside of any methods. If Ben places the variable inside a method it can only be used by that method and therefore becomes an instance variable of that method and not the class. By creating it inside the class and outside the methods it can be used every single time a Book object is created. Therefore, creating an instance variable of serialNumber every time.