Questions and Answers
The _________ construct defines a new type that can group data and methods to form an object.
class
A class' ____________ indicate all operations a class user can perform on the object.
public member methods
What is the difference between accessors and mutators?
A mutator method modifies a class' fields, while an accessor method accesses fields without modification.
A class' private helper method can be called from main(), which is defined in another class.
Signup and view all the answers
A private helper method cannot call another private helper method.
Signup and view all the answers
A constructor that can be called without any arguments is called a _______________.
Signup and view all the answers
The default constructor is called when an object is created of the class type.
Signup and view all the answers
What is the purpose of method overloading?
Signup and view all the answers
Define reference.
Signup and view all the answers
What is the difference between primitive and reference type?
Signup and view all the answers
What are some of the functions wrapper classes allow?
Signup and view all the answers
What does it mean when a wrapper class is immutable?
Signup and view all the answers
For reference variables of wrapper classes, you SHOULD use the equality operators == and != when comparing values.
Signup and view all the answers
What is the difference between autoboxing and unboxing?
Signup and view all the answers
The value of an Integer passed to a method can be modified within the method.
Signup and view all the answers
A parameter of reference type allows a method to access the class members of the object to which the parameter refers.
Signup and view all the answers
Study Notes
Classes and Methods
- A class defines a new type that groups data and methods, forming an object.
- Public member methods indicate all operations that can be performed by a class user on the object.
- The member access operator (".") is used to invoke a method on an object.
Accessors and Mutators
- Mutator methods modify a class's fields (including private fields).
- Accessor methods can access but not modify a class's fields.
- Mutators are known as setters (prefix "set") and accessors as getters (prefix "get").
Method Accessibility
- Private methods of a class cannot be called from
main()
if defined in another class (False). - A private helper method can call another private helper method within the same class (False).
Constructors
- A constructor that takes no arguments is known as a default constructor.
- True: Default constructor is invoked when an object of the class type is created.
- Method overloading allows defining multiple constructors with different parameter types for flexible initialization.
References
- A reference is a variable type that points to an object and stores the object's memory address.
- Reference types include variables of class data types and array types.
Primitive vs. Reference Types
-
Primitive type variables directly store data (e.g.,
int
,double
,char
) and have fixed sizes. - Reference type variables refer to instances of classes (objects) and store references to data in heap space.
Wrapper Classes
- Wrapper classes create objects to store single primitive type values (e.g.,
Integer
,Double
). - They provide methods for converting between primitive types and different number systems, including string representation.
- Wrapper class objects are immutable, meaning their values cannot be changed after creation.
Equality and Comparisons
- Using
==
and!=
for comparing reference variables of wrapper classes is False; instead,equals()
andcompareTo()
should be used for comparing wrapper class objects. - When comparing a wrapper class object to a primitive variable,
==
can be used.
Autoboxing and Unboxing
- Autoboxing is the automatic conversion of primitive types into their corresponding wrapper classes.
- Unboxing is the automatic conversion of wrapper class objects back into their corresponding primitive types.
Method Parameters
- False: An Integer object passed to a method cannot be modified; it is immutable.
- Assigning a new value to an Integer parameter in a method creates a new Integer object.
- A method parameter of reference type allows access to the class members of the referenced object; true since the reference is copied.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge of object-oriented programming concepts with this quiz. Covering topics like classes, member methods, and operators, this quiz will help reinforce your understanding of OOP principles.