Classes and Objects Flashcards
1) Classes as Data Types
A class is basically a data type that can hold both d____ and m_______!
data
methods
2) You can see that there are two aspects to a class:
1: The d_____ that it holds;
2: The t_______s it can perform.
data
tasks
3) Objects
In order to use the methods of a class, you need to create an o__________ of that class.
e.g. as we have been doing in the test classes.
object
4) It’s useful to think of a class as a t____________ from which objects are generated.
an object refers to an individual i_______ of that class.
template
instance
5) Object-oriented programming consists of defining one or more classes that may i_______ with each other.
interact
6) The process of creating an object is called i_______________.
To create an object we use a very special m_________ of the class called a c____________
instantiation
method
constructor
7) The constructor method always has the same n________ as the class.
e.g. Oblong myOblong;
A constructor does NOT r_______ a v_________!
The function of the constructor is to reserve some space in the computer’s m________ to hold the required object.
The new object is stored in a d__________ memory location and the object reference holds the memory address.
name
return a value
memory
different
8) Encapsulation
Encapsulation is the technique of making attributes (variables ,etc) accessible ONLY to the m________ of the same class.
This is a key feature of object-oriented languages.
Encapsulation protects the data in the class by making sure that no program can assign values to the attributes d_______.
methods
directly
9) null
In Java, when a reference is first created without assigning it to a new object in the same line, it is given a special value of null; a null value
indicates that no s______ is allocated.
e.g.
Oblong myOblong; // at this point myOblong has a null value, it is simply a name for a location in m________
myOblong = new Oblong(5.0, 7.5); // create a new Oblong object with length 5.0 and height 7.5
storage
memory
10) What is the key advantage of object-oriented programming over structured programming?
11) What are the differences between primitive data types and object data types?
12) How does a new object affect memory space?
13) How many ways can you create a string object?
14) What is parameter passing by reference?
15) The String Class
Strings are in fact o______ created from a s_____ class!
objects
string