quiz2b Flashcards
T/F: objects are the instances of their classes
true
what declarations does a class contain
data declarations and method declarations
data declarations example
int size, char category
instance variable
a field that’s defined in a class and is allocated when an object is instantiated
class data
static data that all objects share
members
fields and methods that belong to the same class
access modifier
defines the circumstances under which a method or class can be accessed
the most liberal type of access
public access
public access
the usual declaration of classes; methods called by the client of the class
private access
the usual declaration of instance variables; methods called by other methods of the class
T/F: constructors hav a return value
false (constructors have no return value, it will cause compiler errors)
T/F: a class can have several constructors
true
the job of the class constructor
initialize the instance variables of the new object
T/F: a static method can access instance variables
false (static methods are associated with the class, so they don’t have access to the implicit parameter “this”)
T/F: a private method can be accessed by client code
false (nothing outside the class can access private methods)
T/F: a private attribute can be accessed within the equals method
true (it depends because if the equals method is inside, then it can access it, but if it’s outside, the it can’t access it)
T/F: instance attributes should be declared public
false (all instance attributes should be private)
T/F: all instance methods should ALWAYS be declared public
false (you can have private helper methods)
T/F: the return for accessors is usually void
false (an accessor is a getter, so if you have to give it back you can’t return void)
T/F: accessors have no parameters
true (don’t need to return data value)
T/F: mutators have no parameters
false (mutators are setters, so you need to set a value and have its data)
T/F: the return type for mutators is usually void
true (mutators don’t return anything)
T/F: the signature of a method is the return type and parameter list
false (doesn’t include the return type, method name, and parameter list)
has-a relationship
composition (demonstrated by a class that contains another class)
is-a relationships
inheritance (relationship between an object and the class of its member)
toString()
returns a String representation of the object
clone()
creates and returns a copy of the object
equals()
determines if an object is equal to another object
hashCode()
returns a unique int for the object
parent, super, base class
the existing classc
child, sub class
the derived class
T/F: a child class can override the parent implementation
true
can a superclass have multiple subclassses
yes
T/F: subclasses cannot be superclasses of other subclasses
false (subclasses can be superclasses of other subclasses)
T/F: a subclass can inherit directly from multiple superclasses
false (subclasses can only inherit directly from one superclass)
all classes inherit from the Object class
yes
what happens when you define the toString method
overriding an inherited definition
data abstraction
separates the logical properties of a datatype from its implementation
the type of relationship that defines polymorphism
is-a relationship (object of a subclass also being an object of any of the superclasses)
can a class extend more than one parent class
no
are constructors inherited
no (abstract classes cannot be instantiated)
what the efficiency of an algorithm measures
the amount of resources in solving a problem with the input size of n
the preferred implementation
it completes in less time but other consideration constraints impact preference
why you focus on worst case running time
it’s easier to analyze and crucial to applications like gaming, finance, and robotics
what doesn’t affect growth rate
constant factors or lower order terms
T/F: the slower the asymptotic growth rate, the better the algorithm
true
what f(n) O(g(n)) means
f(n) is the growth rate and doesn’t grow more than growth
basic operation of an algorithm
the part of the implementation that most significantly affects the counting steps