Chapter 3: Implementing Classes Flashcards
Where does an object store its data?
an instance variable
What is an instance of a class?
an object of the class
What are the 3 parts that an instance variable declaration consist of?
1.) an access specifier (private)
2.) The type of the instance variable
3.) The name of the instance variable
Write a code for the click method, which advances the counter value by 1
public void click()
{
value = value + 1
}
Write the getValue method
public int getValue()
{
return value;
}
T/F: Private instance values can only be accessed by methods of the same class.
True
What is encapsulation?
the process of hiding implementation details and providing methods for data access
What does encapsulation allow a programmer to do?
use a class without having to know its implementation
What does information hiding make it easier to do?
locate errors and change implementation
What do you need to know before implementing a class
which methods are required
What do constructors do?
set the initial data for objects
What is the name of a constructor?
the name of the class
What are constructors return type?
trick question: constructors have no return type (not even void)
What is the name for a constructor that takes no argument
a no-argument constructor
What is the following an example of?
public BankAccount()
a no-argument constructor