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 (+)