1.
True or False: Constructors do not have a type.
Correct Answer
A. True
Explanation
Constructors do not have a type because they are special methods in a class that are used to initialize objects. Unlike regular methods, constructors do not have a return type, not even void. Their purpose is to set the initial values of the object's attributes and prepare it for use. Therefore, constructors do not have a type associated with them.
2.
The name of a finalizer is ____.
Correct Answer
finalizer
Explanation
A finalizer is a special method in object-oriented programming that is used to perform cleanup operations before an object is garbage collected. It is typically used to release any resources held by the object, such as closing files or freeing up memory. The name of this method is "finalizer".
3.
True or False: Constructors do not have any parameters.
Correct Answer
B. False
Explanation
False. Constructors can have parameters. Parameters allow us to pass values to the constructor when creating an object. This allows us to initialize the object with specific values right from the start.
4.
True or False: A copy constructor is initialized using an existing object.
Correct Answer
A. True
Explanation
A copy constructor is a special constructor that creates a new object by initializing it with an existing object of the same class. It is used to create a copy of an object. Therefore, the statement "A copy constructor is initialized using an existing object" is true.
5.
public, private, and protected are all ____ that alter the behavior of a class.
Correct Answer
modifiers
Explanation
The given correct answer for this question is "modifiers". In object-oriented programming, modifiers are keywords that alter the behavior of a class. The "public" modifier allows the class to be accessed from anywhere, the "private" modifier restricts access to only within the class itself, and the "protected" modifier allows access within the class and its subclasses. These modifiers play a crucial role in encapsulation and controlling the visibility and accessibility of class members.
6.
Java implicitly uses the reference called ____ to refer to both the instance variables and the methods of a class.
Correct Answer
this
Explanation
In Java, the keyword "this" is used as a reference to the current object. It can be used to refer to both the instance variables and the methods of a class. It is often used to differentiate between the instance variables and the parameters or local variables with the same name. The "this" reference allows us to access the current object's members and invoke its methods.
7.
True or False: If a class is not declared public it can only be used within the package it is located in.
Correct Answer
A. True
Explanation
If a class is not declared public, it means that its access modifier is not set to public. In Java, a class with no access modifier is considered to have default access. With default access, the class can only be used within the package it is located in. Therefore, the statement "If a class is not declared public it can only be used within the package it is located in" is true.
8.
____ classes are often used to handle events.
Correct Answer
Inner
Explanation
Inner classes are often used to handle events because they allow for a more organized and modular approach to event handling. By defining an inner class within a class, the event handling logic can be encapsulated within that inner class, keeping it separate from the main class and improving code readability and maintainability. Inner classes also have access to the variables and methods of the outer class, making it easier to handle events and update the state of the application.
9.
True or False: One feature of ADTs is information hiding.
Correct Answer
A. True
Explanation
One feature of Abstract Data Types (ADTs) is information hiding. This means that the internal implementation details of the ADT are hidden from the user, who only has access to the public interface. This allows for encapsulation and protects the integrity of the data. By hiding the implementation, ADTs provide a level of abstraction that allows for easier maintenance and modification of the code.
10.
A(n) ____ inner class definition has no name
Correct Answer
anonymous
Explanation
An anonymous inner class definition has no name because it is defined within another class without explicitly giving it a name. This type of inner class is typically used when a class needs to be created and instantiated only once, and its implementation is not needed elsewhere in the code. By not giving the inner class a name, it allows for a more concise and streamlined code structure.