Docsity

Accredited Test Bank Solution For Java Software Solutions Foundations of Program Design 10, Exams of Technology

Toggle sidebar
bg1
Accredited Test Bank Solution For Java Software
Solutions Foundations of Program Design 10th
edition John Lewis Will
[All Lessons Included]
• Rapid Download
• Quick Turnaround
• Complete Chapters Provided
Complete Chapter Solution Manual
are Included (Ch.1 to Ch.13)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a

Partial preview of the text

Download Accredited Test Bank Solution For Java Software Solutions Foundations of Program Design 10 and more Exams Technology in PDF only on Docsity!

Accredited Test Bank Solution For Java Software

Solutions Foundations of Program Design 10th

edition John Lewis Will

[All Lessons Included]

• Rapid Download

• Quick Turnaround

• Complete Chapters Provided

Complete Chapter Solution Manual

are Included (Ch. 1 to Ch. 13 )

Table of Contents are Given Below

1. Introduction

2. Data and Expressions

3. Using Classes and Objects

4. Writing Classes

5. Conditionals and Loops

6. More Conditionals and Loops

7. Object-Oriented Design

8. Arrays

9. Inheritance

10. Polymorphism

11. Exceptions

12. Recursion

13. Collections

B) protected C) private D) default (package-private) Answer: C Explanation: The 'private' access modifier restricts access to members within their own class. Question 5. Which statement correctly demonstrates method overloading? A) Same method name with different parameters B) Same method name with same parameters C) Different method names performing same task D) Overriding a method from superclass Answer: A Explanation: Method overloading occurs when multiple methods have the same name but different parameter lists within the same class. Question 6. Which control statement is used to execute a block of code repeatedly as long as a condition is true? A) if B) switch C) while D) break Answer: C Explanation: The 'while' loop executes a block repeatedly while its condition remains true. Question 7. What does the 'break' statement do inside a loop? A) Exits the loop immediately B) Continues to the next iteration C) Pauses execution temporarily D) Restarts the loop from the beginning

Answer: A Explanation: 'break' terminates the nearest enclosing loop or switch statement immediately. Question 8. Which of these is an example of an inheritance relationship in Java? A) class Dog extends Animal B) class Car implements Vehicle C) class Employee inherits Person D) class Shape extends Circle Answer: A Explanation: 'extends' indicates inheritance where Dog inherits from Animal. Question 9. What is polymorphism in Java? A) The ability of different classes to be treated as instances of a common superclass B) The process of hiding data members C) The process of creating multiple constructors D) The ability to override private methods Answer: A Explanation: Polymorphism allows objects of different classes to be treated as instances of a common superclass, enabling dynamic method binding. Question 10. Which exception is thrown when dividing an integer by zero? A) NullPointerException B) ArithmeticException C) IOException D) ArrayIndexOutOfBoundsException Answer: B Explanation: Division by zero in Java causes an ArithmeticException to be thrown.

C) They cannot contain abstract methods D) They are instantiated directly Answer: B Explanation: Interfaces can extend multiple interfaces, allowing a form of multiple inheritance. Question 15. Which statement correctly demonstrates an 'if-else' condition? A) if (score > 60) { pass } else { fail } B) switch (score) { case > 60 } C) if (score > 60) { pass } else { fail } D) for (score > 60) { pass } Answer: C Explanation: The syntax 'if (condition) { } else { }' is used for conditional branching. Question 16. Which keyword is used to handle exceptions in Java? A) catch B) try C) handle D) exception Answer: B Explanation: The 'try' block contains code that may throw an exception, which can be handled with 'catch'. Question 17. Which collection class implements a Last-In-First-Out (LIFO) stack? A) ArrayList B) LinkedList C) Stack D) PriorityQueue Answer: C Explanation: The 'Stack' class provides LIFO behavior for managing elements.

Question 18. What is the purpose of the 'super' keyword in Java? A) To access parent class methods or constructors B) To define a superclass C) To create a new object D) To override a method Answer: A Explanation: 'super' refers to the immediate parent class and is used to access its methods or constructors. Question 19. Which method is used to compare two objects for equality in Java? A) equals() B) compareTo() C) == D) compare() Answer: A Explanation: The 'equals()' method compares the contents of two objects for equality. Question 20. Which statement is used to throw an exception explicitly? A) throw B) throws C) catch D) try Answer: A Explanation: The 'throw' statement is used to explicitly throw an exception. Question 21. What is the main benefit of using collections in Java? A) They allow handling multiple objects efficiently B) They improve performance of primitive data types

Explanation: The 'clear()' method removes all elements from the collection. Question 25. Which keyword is used to inherit from a class in Java? A) extends B) implements C) inherits D) super Answer: A Explanation: The 'extends' keyword indicates inheritance from a superclass. Question 26. In Java, which operator is used for logical AND? A) & B) && C) || D)! Answer: B Explanation: '&&' is the logical AND operator, which evaluates to true if both operands are true. Question 27. Which method must be overridden when implementing the Comparable interface? A) compare() B) compareTo() C) equals() D) hashCode() Answer: B Explanation: The 'compareTo()' method defines the natural ordering for objects. Question 28. Which exception is thrown when an array index is accessed outside its bounds? A) NullPointerException

B) IndexOutOfBoundsException C) ArrayIndexOutOfBoundsException D) ArithmeticException Answer: C Explanation: Accessing an invalid array index throws 'ArrayIndexOutOfBoundsException'. Question 29. Which Java feature allows methods to have the same name but different parameters? A) Overloading B) Overriding C) Inheritance D) Encapsulation Answer: A Explanation: Method overloading allows multiple methods with the same name but different parameter lists. Question 30. Which statement is true about encapsulation? A) It hides the internal state of an object B) It allows direct access to data members C) It is achieved using inheritance only D) It prevents class inheritance Answer: A Explanation: Encapsulation hides internal data and exposes only necessary parts through methods. Question 31. Which method is used to start a thread in Java? A) run() B) start() C) execute() D) init() Answer: B

B) switch (color) { if (color == "red") ... } C) switch (color) { default: ... } D) Both A and C Answer: D Explanation: Both options A and C correctly demonstrate switch usage with cases and default. Question 36. Which keyword is used to implement inheritance from an interface? A) extends B) implements C) inherit D) override Answer: B Explanation: Classes implement interfaces using the 'implements' keyword. Question 37. Which Java collection class maintains elements in sorted order? A) HashSet B) TreeSet C) LinkedHashSet D) ArrayList Answer: B Explanation: 'TreeSet' maintains elements in sorted order based on their natural ordering or a comparator. Question 38. Which method must be implemented when creating a custom comparator? A) compare() B) equals() C) compareTo() D) hashCode() Answer: A

Explanation: The 'compare()' method defines custom comparison logic for sorting. Question 39. What is the output of the expression '3 + 4 + " apples"'? A) 7 apples B) 34 apples C) 7 D) "7 apples" Answer: A Explanation: Java evaluates left to right; 3 + 4 = 7, then concatenated with " apples" results in "7 apples". Question 40. Which of these is an example of a checked exception? A) NullPointerException B) IOException C) ArithmeticException D) ArrayIndexOutOfBoundsException Answer: B Explanation: 'IOException' is a checked exception that must be handled or declared. Question 41. Which method is used to convert a primitive data type to its wrapper class object? A) valueOf() B) parse() C) toObject() D) cast() Answer: A Explanation: 'valueOf()' converts primitives to their wrapper class objects. Question 42. Which Java keyword is used to define an abstract class? A) abstract

Explanation: Arrays in Java have a 'length' property, not a method, accessed without parentheses. Question 46. Which keyword is used to handle multiple exceptions in a single catch block? A) catch B) try C) | D) finally Answer: C Explanation: The 'multi-catch' feature uses '|' to handle multiple exceptions in a single catch block. Question 47. Which class provides a thread-safe implementation of the List interface? A) ArrayList B) Vector C) LinkedList D) PriorityQueue Answer: B Explanation: 'Vector' is synchronized and thread-safe. Question 48. Which method is used to compare two strings for equality? A) equals() B) compareTo() C) == D) isEqual() Answer: A Explanation: 'equals()' compares the contents of two strings for equality. Question 49. Which keyword is used to prevent a class from being subclassed? A) final

B) static C) abstract D) private Answer: A Explanation: Declaring a class as 'final' prevents inheritance. Question 50. Which collection class implements a map with key-value pairs? A) ArrayList B) HashMap C) LinkedList D) TreeSet Answer: B Explanation: 'HashMap' stores data in key-value pairs with unique keys. Question 51. Which statement is true about the 'abstract' method? A) It has no implementation in the abstract class B) It provides default behavior C) It can be instantiated directly D) It must be private Answer: A Explanation: Abstract methods have no implementation and must be overridden in subclasses. Question 52. Which of the following is a correct way to declare a generic class? A) class Box { } B) class Box(T) { } C) class Box<> { } D) class Box[] { } Answer: A

B) pause() C) wait() D) suspend() Answer: A Explanation: 'sleep()' pauses the current thread for a specified period. Question 57. Which class in Java provides a thread-safe implementation of queues? A) PriorityQueue B) ConcurrentLinkedQueue C) LinkedList D) ArrayDeque Answer: B Explanation: 'ConcurrentLinkedQueue' is thread-safe and supports concurrent access. Question 58. Which method is used to get the current system time in milliseconds? A) getTime() B) currentTimeMillis() C) now() D) time() Answer: B Explanation: 'System.currentTimeMillis()' returns the current time in milliseconds. Question 59. Which keyword is used in Java to create a constant value? A) static B) final C) const D) constant Answer: B

Explanation: 'final' is used to declare constants whose values cannot change. Question 60. Which statement correctly demonstrates the use of a do-while loop? A) do { statement } while (condition); B) while (condition) { statement } C) for (initialization; condition; increment) { statement } D) if (condition) { statement } Answer: A Explanation: The 'do-while' loop executes its body at least once before checking the condition. Question 61. Which method is used to convert an object to its string representation? A) toString() B) getString() C) display() D) print() Answer: A Explanation: 'toString()' returns a string representing the object. Question 62. Which keyword is used to implement multiple inheritance in Java? A) extends B) implements C) inherit D) multiple Answer: B Explanation: Java achieves multiple inheritance through implementing multiple interfaces. Question 63. Which method is used to add all elements from one collection to another? A) add()