CMSC 131 (Summer 2019) Week 07 Study Questions Flashcards
In what kind of methods does it make sense to use “this”?
Instance methods and constructors.
What does “this” refer to?
The “current object”.
If you do not write any constructors, what values will instance variables of the following primitive types be assigned: int, double, boolean, char ?
0 for int, 0.0 for double, false for boolean, ASCII code 0 for char
If you do not write any constructors, what values will instance variables that are references by assigned?
null
Under what circumstances will Java provide a default constructor for you automatically?.
If you do not write any constructors yourself.
What is a copy constructor? Give an example.
The copy constructor accepts an argument that is the same type as the object being constructed. It initializes the fields of the current object to match that of the parameter.
Example:
public Cat(Cat x) { numWhiskers = x.numWhiskers; name = x.name; }
What is a Stack (in general, not just in Java)?
A stack is a simple linear data type in which elements are both inserted (“pushed”) and removed (“popped”) from the same end. (We usually picture the stack vertically, and say that we “push” and “pop” items from the top.)
When you push an entry into the stack does it go on the top or bottom?
top
When you pop an entry from the stack, does it come off the top or bottom?
top
True/False: In java, when you pass a reference variable as an argument to a method, it is possible for the method to modify the object to which the variable refers.
TRUE
What does API stand for?
Application Programming Interface
If someone showed you a Java class, how can you quickly identify which members were part of the API for that class?
Look for “public” members.
If a member is declared as public, can it be accessed from inside the same class?
YES.
If a member is declared as public, can it be accessed from another class?
YES.
If a member is declared as private, can it be accessed from inside the same class?
YES