Multiple choice
✓ What is a default constructor in Java? *
A constructor with no parameters provided by Java if none are defined
A constructor with default values for all attributes
A constructor that is automatically called by Java
A constructor that initializes all attributes to null
How does the ‘private’ access modifier impact class members in Java? 1/1
Allows access within its own package and by subclasses
Makes a class, field, method, or constructor accessible from any other class
Allows access only within the same package
Restricts visibility to only within the class where it is declared
What is the significance of access modifiers in Java programming? * 1/1
To automatically generate getter and setter methods
To control the visibility and accessibility of classes, fields, methods, and constructors
To hide the internal details of a class
To define and identify properties in Java
How does encapsulation promote data integrity in Java programming? 1/1
By controlling the access to the internal state of an object through well-defined methods
By automatically generating getter and setter methods
By defining and identifying properties in Java
By hiding the implementation details from external classes
What do setter methods allow you to do in Java?*
• Modify the values of properties
Provide access to the values of properties from outside the class
Display the values of properties
Control the visibility of class members
Which term is used to refer to fields or variables within a class that represent the state or characteristics
of objects in Java?
Properties
Methods
Constructors
Annotations
Which access modifier allows access within its own package and by subclasses in Java?
Default
Protected
Public
Private
What do properties in Java usually refer to? *
Fields or variables within a class that represent the state or characteristics of objects
Annotations like @Getter and @Setter
Constructors in Java classes
Methods that provide access to the values of properties
Which method allows you to initialize properties during object creation in *1/1 Java?
Getter methods
Setter methods
Constructor
Display Properties method
Which annotation in Java can automatically generate getter methods for *1/1 fields?
@Getter
@Setter
@Encapsulate
@Access
What do getter methods provide access to in Java? *
Modify the values of properties
Display the values of properties
Hide the implementation details from external classes
Values of properties from outside the class
Which access modifier allows access only within the same class in Java? * 1/1
Public
Private
Default
Protected
What is the role of the ‘protected’ access modifier in Java?*
Allows access within its own package and by subclasses
Makes a class, field, method, or constructor accessible from any other class
Restricts visibility to only within the class where it is declared
Allows access only within the same package
1/1
✔ How do access modifiers help in Java programming?*
Define and identify properties in Java
Automatically generate getter and setter methods
Control the visibility of class members.
Hide the implementation details from external classes
1/1
What is the purpose of encapsulation in Java? *
Automatically generate getter and setter methods
Control the visibility of class members
Define and identify properties in Java
Hide the internal details of a class and expose only what is necessary for other classes to use
What is the purpose of getter methods in Java? *
• Provide access to the values of properties from outside the class
Modify the values of properties
Hide the implementation details from external classes
Display the values of properties
How do setter methods contribute to Java programming?
By providing access to the values of properties from outside the class
By displaying the values of properties
By controlling the visibility of class members.
By allowing modification of the values of properties
✓ What do methods define in a Java class?
Variables that store data
Actions or behaviors that can be performed on objects
Loops that repeat
Constructors that initialize objects
In Java, what keyword is used to declare a class? *
Ovariable
Method
Object
Class
What is the purpose of constructor chaining in Java?*
To call loops within a class
To call variables within a class
To call methods within a class
• To call other constructors within a class
What is the purpose of constructor chaining in Java? *
To call loops within a class
To call variables within a class
To call methods within a class
To call other constructors within a class
Which keyword is used to create an instance of a class in Java? *
Create
New
Instance
Initialize
What are fields in the context of a Java class? *
⚫Variables that represent the state of an object
Methods that perform specific actions
Constructors in Java
Loops in Java
What is a class in Java?*
A blueprint for creating objects
A variable in Java
A loop in Java
A method in Java
What is the purpose of a constructor in Java? *
To declare variables in a class
To define methods in a class
To create loops in Java
To initialize the object’s
How is a copy construction used in java?
To create a new object by copying values from an existing object of the same class
To rename an object
To compare two objects
To delete an object
What are methods in the context of a Java class? *
1/1
Functions defined within a class that perform specific actions
Loops in Java
Variables that represent the state of an object
Constructors in Java
✓ When is a constructor called in Java?*
1/1
When an object is created
When a method is called
When a variable is declared
When a loop is executed
What is a constructor in Java? *
A keyword in Java
A loop in Java
A variable in Java
A special method called when an object is created
What is a copy constructor in Java? *
Used to compare two objects in Java
Used to rename an object in Java
Used to delete an object in Java
Used to create a new object by copying values from an existing object of the same class
How are objects created in Java?*
Using the class keyword
Using the extends keyword
Using the main method
• Using the new keyword followed by a constructor