FULL QUIZ Flashcards

1
Q

What is the purpose of creating classes in Java?
A) To complicate programming tasks.
B) To model real-world objects and encapsulate related data and behaviors.
C) To confuse developers with unnecessary complexities.
D) To minimize code readability.

A

B) To model real-world objects and encapsulate related data and behaviors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following is NOT an example of a built-in Java class?
A) String class
B) Math class
C) Account class
D) Scanner class

A

C) Account class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does an object represent in Java?
A) A variable.
B) A method.
C) An entity with attributes and behaviors defined by classes.
D) An abstract concept.

A

C) An entity with attributes and behaviors defined by classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are attributes in the context of Java objects?
A) Actions an object can perform.
B) Characteristics of an object.
C) Variables used within a method.
D) Constants defined within a class.

A

B) Characteristics of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which visibility modifier is commonly used for attributes in Java classes?
A) public
B) private
C) protected
D) static

A

B) private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which keyword is used to declare a static variable in Java?
A) final
B) static
C) const
D) staticvar

A

B) static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is encapsulation in Java?
A) Combining data and methods into a single unit within an object.
B) Protecting data from external access and inappropriate modification.
C) Exposing all class members publicly.
D) Allowing direct access to instance variables.

A

A) Combining data and methods into a single unit within an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are static variables different from instance variables?
A) Static variables are unique to each instance of a class.
B) Instance variables are shared among all instances of a class.
C) Static variables are declared using the ‘this’ keyword.
D) Instance variables are declared using the ‘static’ keyword.

A

B) Instance variables are shared among all instances of a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of a driver class in Java?
A) To drive a car object.
B) To test parts of code under controlled conditions.
C) To provide static variables to other classes.
D) To confuse developers.

A

B) To test parts of code under controlled conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which method is commonly used to test the functionality of a Java class?
A) main()
B) test()
C) drive()
D) run()

A

A) main()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the ‘private’ keyword signify in Java class attributes?
A) They can be accessed by any class.
B) They are only accessible within the same package.
C) They are accessible only within the same class.
D) They are accessible by subclasses.

A

C) They are accessible only within the same class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which of the following is an example of a behavior of an object?
A) name
B) age
C) printDetails()
D) totalPersons

A

C) printDetails()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the purpose of the Scanner class in Java?
A) To format decimal numbers.
B) To perform mathematical calculations.
C) To read input from the user.
D) To manipulate strings.

A

C) To read input from the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which class is commonly used to format decimal numbers in Java?
A) String class
B) Math class
C) Scanner class
D) DecimalFormat class

A

D) DecimalFormat class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of the ‘final’ keyword in Java?
A) To indicate that a method cannot be overridden.
B) To indicate that a variable cannot be changed.
C) To indicate that a class cannot be instantiated.
D) To indicate that a method cannot be accessed from outside the class.

A

A) To indicate that a method cannot be overridden.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which method is used to deposit money into a bank account in the Account class?
A) withdraw()
B) addInterest()
C) getBalance()
D) deposit()

A

D) deposit()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does the ‘public’ modifier signify in Java?
A) The method can only be accessed within the same class.
B) The method can be accessed by any class.
C) The method can only be accessed within the same package.
D) The method can be accessed only within subclasses.

A

B) The method can be accessed by any class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the scope of static variables in Java?
A) They are unique to each instance of a class.
B) They exist only within the same method.
C) They exist from when the class is loaded until the program ends.
D) They are shared among all instances of a class.

A

C) They exist from when the class is loaded until the program ends.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Which method is used to withdraw money from a bank account in the Account class?
A) deposit()
B) addInterest()
C) getBalance()
D) withdraw()

A

D) withdraw()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the purpose of the ‘import’ statement in Java?
A) To include external libraries in the program.
B) To declare a new class.
C) To import static variables.
D) To comment out code temporarily.

A

A) To include external libraries in the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is encapsulation in Java?
A) Combining data and methods into a single unit within an object.
B) Protecting operations and attributes within an object, allowing state changes only through defined methods.
C) Grouping related ideas into a unit referred to by a single name.
D) The code executed to perform an operation.

A

B) Protecting operations and attributes within an object, allowing state changes only through defined methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which term refers to a data value significant to an object in Java?
A) Encapsulation
B) Operation
C) Attribute
D) Method

A

C) Attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the purpose of a constructor in Java?
A) To initialize new objects.
B) To manage a coherent set of tasks.
C) To clean up before an object is destroyed.
D) To report state without changing it.

A

A) To initialize new objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Which of the following accurately represents the visibility symbol in UML for a public member?
A) Private (-)
B) Public (+)
C) Protected (#)
D) Default (~)

A

B) Public (+)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is the primary feature of the ArrayList class in Java?
A) It represents a dynamically resizable array.
B) It allows for object destruction.
C) It provides basic list operations only.
D) It has a fixed size.

A

A) It represents a dynamically resizable array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is the purpose of the ‘remove’ method in the ArrayList class?
A) To dynamically resize the array.
B) To remove items from the list.
C) To access items in the list.
D) To add items to the list.

A

B) To remove items from the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Which method is commonly used to add items to an ArrayList?
A) get()
B) remove()
C) add()
D) size()

A

C) add()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What does the term “self-messaging” refer to in Java?
A) A call from one object to another to execute a method.
B) An object calling its own methods.
C) Data passed to methods.
D) Dynamically resizable array.

A

B) An object calling its own methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the purpose of the ‘isEmpty’ method in the ArrayList class?
A) To check if the list is null.
B) To check if the list is empty.
C) To remove all items from the list.
D) To get the size of the list.

A

B) To check if the list is empty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Which type of method in Java reports state without changing it?
A) Accessors
B) Mutators
C) Constructors
D) Destructors

A

A) Accessors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is the purpose of the ‘addInterest’ method in the Account class?
A) To deposit money into the account.
B) To withdraw money from the account.
C) To calculate and add interest to the account balance.
D) To initialize a new account.

A

C) To calculate and add interest to the account balance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Which method is used to withdraw money from a bank account in the Account class?
A) deposit()
B) addInterest()
C) getBalance()
D) withdraw()

A

D) withdraw()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is the primary goal of designing classes in Java?
A) To handle a single part of the functionality.
B) To make classes difficult to reuse.
C) To avoid abstractions.
D) To confuse developers.

A

A) To handle a single part of the functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Which method is commonly used to test the functionality of a Java class?
A) main()
B) test()
C) drive()
D) run()

A

A) main()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Which term refers to functionalities an object can perform in Java?
A) Attribute
B) Operation
C) Encapsulation
D) Method

A

D) Method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What is the primary purpose of a constructor in Java?
A) To initialize new objects.
B) To clean up before an object is destroyed.
C) To manage a coherent set of tasks.
D) To report state without changing it.

A

A) To initialize new objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Which keyword is used to declare a static variable in Java?
A) final
B) static
C) const
D) staticvar

A

B) static

38
Q

What is the scope of static variables in Java?
A) They are unique to each instance of a class.
B) They exist only within the same method.
C) They exist from when the class is loaded until the program ends.
D) They are shared among all instances of a class.

A

C) They exist from when the class is loaded until the program ends.

39
Q

Which of the following is NOT an example of a built-in Java class?
A) String class
B) Math class
C) Account class
D) Scanner class

A

C) Account class

40
Q

What is the purpose of the ‘final’ keyword in Java?
A) To indicate that a method cannot be overridden.
B) To indicate that a variable cannot be changed.
C) To indicate that a class cannot be instantiated.
D) To indicate that a method cannot be accessed from outside the class.

A

B) To indicate that a variable cannot be changed.

41
Q

Which term refers to a unit referred to by a single name in Java?
A) Encapsulation
B) Method
C) Class
D) Operation

A

C) Class

42
Q

What does the term “Message” refer to in Java?
A) A call from one object to another to execute a method.
B) An object calling its own methods.
C) Data passed to methods.
D) Dynamically resizable array.

A

A) A call from one object to another to execute a method.

43
Q

Which method is used to remove items from an ArrayList?
A) get()
B) remove()
C) add()
D) size()

A

B) remove()

44
Q

What does the ‘private’ visibility modifier signify in Java class attributes?
A) They can be accessed by any class.
B) They are only accessible within the same package.
C) They are accessible only within the same class.
D) They are accessible by subclasses.

A

C) They are accessible only within the same class.

45
Q

Which of the following is NOT a method type in Java?
A) Accessors
B) Mutators
C) Constructors
D) Destructors

A

D) Destructors

46
Q

What is the purpose of the ‘run’ method in the Dog class?
A) To initialize a new Dog object.
B) To report state without changing it.
C) To simulate a running behavior.
D) To add interest to the Dog’s attributes.

A

C) To simulate a running behavior.

47
Q

What is the primary purpose of the ‘bark’ method in the Dog class?
A) To withdraw money from the Dog’s account.
B) To calculate and add interest to the Dog’s attributes.
C) To report state without changing it.
D) To simulate a barking behavior.

A

D) To simulate a barking behavior.

48
Q

Which term refers to functionalities an object can perform in Java?
A) Attribute
B) Operation
C) Encapsulation
D) Method

A

D) Method

49
Q

What is the primary purpose of the ‘chase’ method in the Dog class?
A) To initialize a new Dog object.
B) To report state without changing it.
C) To add interest to the Dog’s attributes.
D) To simulate a chase behavior.

A

D) To simulate a chase behavior.

50
Q

Which type of method in Java changes the state of an object?
A) Accessors
B) Mutators
C) Constructors
D) Destructors

A

B) Mutators

51
Q

What is an association in Java?
A) A link between two classes that allows instances of one class to connect and communicate with instances of another.
B) A way to represent physical or conceptual connections between object instances.
C) A type of whole-part relationship between classes.
D) A method used to initialize new objects.

A

A) A link between two classes that allows instances of one class to connect and communicate with instances of another.

52
Q

What is the purpose of a unidirectional association?
A) Both classes know about and interact with each other.
B) Only one class knows about and interacts with another class.
C) It represents a strong coupling between classes.
D) It facilitates communication between two objects.

A

B) Only one class knows about and interacts with another class.

53
Q

Which UML representation indicates a composition relationship?
A) Unfilled diamond at the whole class end of the association line.
B) Filled diamond at the whole class end of the association line.
C) Dashed arrow from the dependent class to the class it uses.
D) A solid line connecting two classes.

A

B) Filled diamond at the whole class end of the association line.

54
Q

What does the term “dependency” refer to in Java?
A) A link between two classes that allows instances of one class to connect and communicate with instances of another.
B) A type of whole-part relationship between classes.
C) Indicating temporary use of an instance from another class.
D) Facilitating the use of primitive types where objects are required.

A

C) Indicating temporary use of an instance from another class.

55
Q

Which of the following is NOT a wrapper class in Java?
A) Integer
B) Double
C) Float
D) String

A

D) String

56
Q

What is autoboxing in Java?
A) Automatically converting a wrapper class object into its corresponding primitive type.
B) Automatically converting a primitive type into its corresponding wrapper class object.
C) Automatically converting between different wrapper classes.
D) Automatically converting between primitive types.

A

B) Automatically converting a primitive type into its corresponding wrapper class object.

57
Q

What is unboxing in Java?
A) Automatically converting a wrapper class object into its corresponding primitive type.
B) Automatically converting a primitive type into its corresponding wrapper class object.
C) Automatically converting between different wrapper classes.
D) Automatically converting between primitive types.

A

A) Automatically converting a wrapper class object into its corresponding primitive type.

58
Q

Which of the following statements about aggregation is true?
A) It represents a strong coupling between classes.
B) The parts can exist independently of the whole.
C) If the whole is destroyed, the parts are also destroyed.
D) It is represented by a filled diamond in UML.

A

B) The parts can exist independently of the whole.

59
Q

What is the primary purpose of the ‘setResidence’ method in the Person class?
A) To establish a bidirectional association between classes.
B) To add a residence to the person’s list of residences.
C) To establish a unidirectional association between classes.
D) To set the residence of a person to a specified value.

A

C) To establish a unidirectional association between classes.

60
Q

Which keyword is used to represent a composition relationship in UML?
A) +
B) -
C) #
D) Filled diamond

A

D) Filled diamond

61
Q

What is the purpose of the ‘clean’ method in the Residence class?
A) To clean up before an object is destroyed.
B) To remove items from the list of residences.
C) To clean the residence.
D) To clean up temporary dependencies.

A

C) To clean the residence.

62
Q

Which type of association suggests potential links between objects of participating classes?
A) Dependency
B) Unidirectional Association
C) Bidirectional Association
D) Aggregation

A

D) Aggregation

63
Q

What is the main difference between aggregation and composition?
A) Aggregation represents a whole-part relationship where parts cannot exist independently of the whole.
B) Composition represents a whole-part relationship where parts can exist independently of the whole.
C) Aggregation represents a weaker form of coupling between classes.
D) Composition represents a bidirectional association between classes.

A

B) Composition represents a whole-part relationship where parts can exist independently of the whole.

64
Q

Which of the following is NOT an example of a multiplicity relationship?
A) 1 to 1
B) 1 to Many
C) Many to Many
D) 1 to All

A

D) 1 to All

65
Q

What does the ‘ArrayList’ class facilitate in Java?
A) Dynamic resizing of arrays
B) Creation of wrapper classes
C) Establishing associations between objects
D) Managing dependency between classes

A

A) Dynamic resizing of arrays

66
Q

What is the purpose of the ‘add’ method in the ArrayList class?
A) To remove items from the list
B) To add items to the list
C) To access items in the list
D) To check if the list is empty

A

B) To add items to the list

67
Q

Which method is commonly used to retrieve items from an ArrayList?
A) get()
B) add()
C) remove()
D) size()

A

A) get()

68
Q

What is the primary goal of designing classes in Java?
A) To handle a single part of the functionality
B) To confuse developers
C) To avoid abstractions
D) To make classes difficult to reuse

A

A) To handle a single part of the functionality

69
Q

Which of the following accurately represents autoboxing in Java?
A) Converting a wrapper class object into its corresponding primitive type
B) Converting a primitive type into its corresponding wrapper class object
C) Converting between different wrapper classes
D) Converting between primitive types

A

B) Converting a primitive type into its corresponding wrapper class object

70
Q

What is the main purpose of wrapper classes in Java?
A) To provide a way to treat primitive data types as objects
B) To represent physical or conceptual connections between object instances
C) To establish associations between classes
D) To clean up before an object is destroyed

A

A) To provide a way to treat primitive data types as objects

71
Q

What is the purpose of inheritance in Java?

A) To allow a hierarchy of classes where derived classes inherit features from their base classes.
B) To restrict access to certain methods in derived classes.
C) To prevent code reusability.
D) To promote tight coupling between classes.

A

A) To allow a hierarchy of classes where derived classes inherit features from their base classes.

72
Q

Which of the following best describes method overriding?

A) Creating a new method in the superclass.
B) Modifying inherited methods in subclasses to perform differently.
C) Hiding methods in the superclass.
D) Overloading methods in subclasses.

A

B) Modifying inherited methods in subclasses to perform differently.

73
Q

What does polymorphism allow in Java?

A) Only one subclass of a superclass.
B) Treating subclasses of the same superclass as objects of the superclass.
C) Creating multiple instances of a superclass.
D) Restricting subclass-specific behaviors.

A

B) Treating subclasses of the same superclass as objects of the superclass.

74
Q

When is late binding (dynamic binding) used?

A) Methods resolved at compile time.
B) Methods resolved at runtime.
C) Methods resolved during debugging.
D) Methods resolved during testing.

A

B) Methods resolved at runtime.

75
Q

What does casting an object in Java mean?

A) Creating a new object from another object.
B) Removing a method from an object.
C) Converting an object from one type to another.
D) Comparing two objects for equality.

A

C) Converting an object from one type to another.

76
Q

Which of the following statements about upcasting and downcasting is true?

A) Downcasting is always implicit.
B) Upcasting is potentially unsafe.
C) Upcasting is always safe.
D) Downcasting is always safe.

A

C) Upcasting is always safe.

77
Q

What is the root class in Java from which all other classes inherit implicitly?

A) java.util.Root
B) java.lang.Object
C) java.class.Root
D) java.root.Class

A

B) java.lang.Object

78
Q

What is the purpose of the toString() method in the Object class?

A) Compares two objects for equality.
B) Returns a string representation of the object.
C) Calculates the hash code of the object.
D) Initializes an object.

A

B) Returns a string representation of the object.

79
Q

When is early binding (static binding) used in Java?

A) Methods resolved at compile time.
B) Methods resolved at runtime.
C) Methods resolved during debugging.
D) Methods resolved during testing.

A

A) Methods resolved at compile time.

80
Q

What does the java.lang.Class class provide in Java?

A) Access to database operations.
B) Access to file system operations.
C) Access to class metadata at runtime.
D) Access to network operations.

A

C) Access to class metadata at runtime.

81
Q

Which of the following UML notations represents inheritance?

A) Hollow triangle at the subclass end of the association line.
B) Filled triangle at the subclass end of the association line.
C) Hollow diamond at the superclass end of the association line.
D) Filled diamond at the superclass end of the association line.

A

B) Filled triangle at the subclass end of the association line.

82
Q

What does the equals(Object obj) method in the Object class do?

A) Compares two objects based on their references.
B) Compares two objects based on their attributes.
C) Determines if an object is an instance of a specific class.
D) Determines if two objects are equal based on their attributes.

A

D) Determines if two objects are equal based on their attributes.

83
Q

What does the hashCode() method in the Object class do?

A) Returns the hash code of an object.
B) Compares two objects based on their hash codes.
C) Initializes an object.
D) Returns the class name of an object.

A

A) Returns the hash code of an object.

84
Q

When is casting required in Java?

A) Casting is never required in Java.
B) Casting is required for every object.
C) Casting is required when converting between primitive types.
D) Casting is required when downcasting objects.

A

D) Casting is required when downcasting objects.

85
Q

What is the purpose of the writeLetter() method in the Secretary class?

A) Applies for vacation.
B) Writes a letter.
C) Shows working hours.
D) Shows salary.

A

B) Writes a letter.

86
Q

What is the output of the following code?

Employee emp = new Lawyer();
emp.applyForVacation();
A) Use the yellow form
B) Use the pink form
C) I receive 2 weeks vacation
D) I receive 3 weeks vacation

A

B) Use the pink form

87
Q

What does the showSalary() method in the Lawyer class do?

A) Shows the working hours.
B) Shows the salary.
C) Applies for vacation.
D) Shows the vacation weeks.

A

D) Shows the vacation weeks.

88
Q

What will happen if you attempt to downcast an object to an incompatible type?

A) A compile-time error will occur.
B) A runtime error will occur.
C) The downcast will be successful.
D) The upcast will be successful.

A

B) A runtime error will occur.

89
Q

What is the relationship between a superclass and its subclasses in terms of inheritance?

A) A superclass inherits features from its subclasses.
B) Subclasses inherit features from their superclass.
C) Subclasses override features of their superclass.
D) A superclass and its subclasses have no relationship.

A

B) Subclasses inherit features from their superclass.

90
Q

What is the purpose of method overriding in Java?

A) To restrict access to superclass methods.
B) To create new methods in subclasses.
C) To modify inherited methods to perform differently.
D) To prevent polymorphism.

A

C) To modify inherited methods to perform differently.