FULL QUIZ Flashcards
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.
B) To model real-world objects and encapsulate related data and behaviors.
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
C) Account class
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.
C) An entity with attributes and behaviors defined by classes.
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.
B) Characteristics of an object.
Which visibility modifier is commonly used for attributes in Java classes?
A) public
B) private
C) protected
D) static
B) private
Which keyword is used to declare a static variable in Java?
A) final
B) static
C) const
D) staticvar
B) static
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) Combining data and methods into a single unit within an object.
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.
B) Instance variables are shared among all instances of a class.
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.
B) To test parts of code under controlled conditions.
Which method is commonly used to test the functionality of a Java class?
A) main()
B) test()
C) drive()
D) run()
A) main()
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.
C) They are accessible only within the same class.
Which of the following is an example of a behavior of an object?
A) name
B) age
C) printDetails()
D) totalPersons
C) printDetails()
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.
C) To read input from the user.
Which class is commonly used to format decimal numbers in Java?
A) String class
B) Math class
C) Scanner class
D) DecimalFormat class
D) DecimalFormat class
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) To indicate that a method cannot be overridden.
Which method is used to deposit money into a bank account in the Account class?
A) withdraw()
B) addInterest()
C) getBalance()
D) deposit()
D) deposit()
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.
B) The method can be accessed by any class.
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.
C) They exist from when the class is loaded until the program ends.
Which method is used to withdraw money from a bank account in the Account class?
A) deposit()
B) addInterest()
C) getBalance()
D) withdraw()
D) withdraw()
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) To include external libraries in the program.
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.
B) Protecting operations and attributes within an object, allowing state changes only through defined methods.
Which term refers to a data value significant to an object in Java?
A) Encapsulation
B) Operation
C) Attribute
D) Method
C) Attribute
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) To initialize new objects.
Which of the following accurately represents the visibility symbol in UML for a public member?
A) Private (-)
B) Public (+)
C) Protected (#)
D) Default (~)
B) Public (+)
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) It represents a dynamically resizable array.
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.
B) To remove items from the list.
Which method is commonly used to add items to an ArrayList?
A) get()
B) remove()
C) add()
D) size()
C) add()
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.
B) An object calling its own methods.
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.
B) To check if the list is empty.
Which type of method in Java reports state without changing it?
A) Accessors
B) Mutators
C) Constructors
D) Destructors
A) Accessors
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.
C) To calculate and add interest to the account balance.
Which method is used to withdraw money from a bank account in the Account class?
A) deposit()
B) addInterest()
C) getBalance()
D) withdraw()
D) withdraw()
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) To handle a single part of the functionality.
Which method is commonly used to test the functionality of a Java class?
A) main()
B) test()
C) drive()
D) run()
A) main()
Which term refers to functionalities an object can perform in Java?
A) Attribute
B) Operation
C) Encapsulation
D) Method
D) Method
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) To initialize new objects.