





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






























Format Professional practice / study guide
Question count 100
Answer choices 4 per question; globally checked for duplicate choice text
Scope Java fundamentals through object-oriented design, debugging, exceptions, polymorphism and testing
Important scope note: Public web evidence shows that “CS 110” is used for different courses at different institutions. This guide therefore does not claim to reproduce an official university assignment answer key. It is an independently written practice resource aligned to verified Java/OOP learning themes.
The requested title combines a CS 110 course code with Java/OOP terminology, but course codes are institution-specific. Research found multiple materially different CS 110 courses. NUST currently lists CS-110 as Fundamentals of Computer Programming and CS-212 as Object Oriented Programming; Swansea describes CS-110 Programming 1 as a Java module; and Northern Arizona University uses CS 110 for an introductory course spanning OOP, Java, Python and Alice. Accordingly, this publication avoids invented university-specific assignment numbers, deadlines, or claims of official answers.
National University of Sciences and Technology (NUST), CS-110 Fundamentals of Computer Programming Official NUST course-content PDF; identifies CS-110 as a 3-1 introductory programming course and describes C++-based fundamentals. https://nust.edu.pk/wp-content/uploads/course_content_files/870611388_CS-110%20Fundamentals%20of%20Computer%20Programming.pdf
NUST BS Computer Science study plan Official NUST curriculum page; places CS-110 Fundamentals of Computer Programming before CS-212 Object Oriented Programming. https://nbc.nust.edu.pk/department-page/cs-tentative-study-plan/
NUST CS-212 Object Oriented Programming course outline Official NUST course outline; states that Java is the major language used for OOP and covers classes, inheritance, encapsulation, polymorphism, abstraction, static members and object construction. https://nust.edu.pk/wp-content/uploads/course_content_files/525588090_CS%20212%20Course_ouline%20-%20Aimal%20Rextin.pdf
Swansea University, CS-110 Programming 1 Official university course description covering Java basics, arrays, ArrayLists, objects, classes, methods, loops and laboratory work. https://www.swansea.ac.uk/staff/n.a.harman/
Northern Arizona University, CS 110 Course Syllabus Official syllabus example demonstrating that CS 110 is institution-specific and may combine introductory programming, OOP, Java and other languages. https://www.cefns.nau.edu/~pek7/cs110/CS%20110%20Course%20Syllabus.html
Use the questions as lab preparation, self-testing, code-reading practice, or review. For code-tracing items, work through state changes before checking the answer. For design questions, identify the underlying relationship—encapsulation, inheritance, interface contract, polymorphism, or composition—rather than memorizing terminology.
Focus: Java Foundations. Questions progress from direct concept recognition toward application and code reasoning.
A. It stores every variable in a permanent database for later executions. B. It automatically rewrites classes into interfaces before compilation. C. It converts bytecode directly into machine instructions before a program starts. D. It translates Java source into bytecode that the JVM can execute.
Correct Answer: D. It translates Java source into bytecode that the JVM can execute.
Explanation: The Java compiler translates source code into JVM bytecode, normally stored in a .class file. The JVM then loads and executes that bytecode. Compilation and runtime execution are distinct stages.
Key Takeaway: Separate compilation from execution: javac produces bytecode; the JVM runs it.
A. public void start(String[] args) B. private final int main(String[] args) C. static protected String main(int[] args) D. public static void main(String[] args)
Correct Answer: D. public static void main(String[] args)
Explanation: The conventional entry point is public static void main(String[] args). public makes it accessible to the launcher, static allows invocation without constructing an object, void specifies no return value, and String[] receives command-line arguments.
Key Takeaway: Know the exact role of each keyword in the Java entry point.
A. InventoryReport.txt B. Inventory_Report.class C. InventoryReport.java D. ReportInventory.java
Correct Answer: C. InventoryReport.java
Explanation: A public top-level class normally must have a source filename matching the class name, followed by .java. The compiled bytecode is a separate artifact.
Key Takeaway: Public top-level class name and source filename should match.
A. \ starts a comment and automatically comments the rest of the file.
B. is the ordinary syntax for all Java comments. C. // starts a single-line comment; /* ... */ can span lines. D. # starts a standard Java comment that lasts until the next statement.
Correct Answer: C. // starts a single-line comment; /* ... */ can span lines.
Explanation: Java supports // for single-line comments and /* ... */ for block comments. The # and HTML-style comment markers are not Java comment syntax.
Key Takeaway: Use Java's own comment delimiters rather than borrowing syntax from another language.
Focus: Variables & Data Types. Questions progress from direct concept recognition toward application and code reasoning.
A. Int seats <- 18; B. integer seats := 18; C. number seats = 18; D. int seats = 18;
Correct Answer: D. int seats = 18;
Explanation: int is Java's primitive integer type, and assignment uses =. The other declarations use syntax or type names that are not valid Java.
Key Takeaway: Java primitive declarations use a type, variable name, and optional initialization.
A. bit B. boolean C. truthValue D. logical
Correct Answer: B. boolean
Explanation: Java's primitive boolean type represents true or false values. The other names are not Java primitive types.
Key Takeaway: Use boolean for two-state logical conditions.
Correct Answer: D. 12
Explanation: The plus operator adds integer operands, so 7 + 5 evaluates to 12. The digits are not concatenated because both operands are numeric ints.
Correct Answer: C. 13
Explanation: The compound assignment x += 9 is equivalent to x = x + 9, so 4 becomes 13.
Key Takeaway: Compound assignment updates the existing value using the operator on the left.
A. equals B. == C. = D. <>
Correct Answer: B. ==
Explanation: For primitive values, == compares values. A single = performs assignment; equals is a method used by objects; <> is not Java's equality operator.
Key Takeaway: Distinguish assignment from comparison.
Focus: Conditionals. Questions progress from direct concept recognition toward application and code reasoning.
A. Both branches execute once. B. Neither branch can execute because 31 is not an integer literal. C. The B branch executes. D. The A branch executes.
Correct Answer: D. The A branch executes.
Explanation: 31 is greater than 30, so the condition is true and the first branch runs. An if/else chooses one branch based on the condition.
Key Takeaway: Evaluate the condition before deciding which branch runs.
A. try B. while C. import D. switch
Correct Answer: D. switch
Explanation: switch is designed for selecting among discrete cases. while repeats based on a condition, try handles exceptions, and import makes types available.
Key Takeaway: Use switch when one expression is matched against discrete cases.
A. Another condition to test only if earlier conditions were false. B. A second method declaration inside the first branch. C. A loop that repeats the previous condition indefinitely. D. A way to force all earlier branches to execute.
Correct Answer: A. Another condition to test only if earlier conditions were false.
Explanation: An else if adds another condition that is considered only when the preceding if/else-if conditions have not matched.
Key Takeaway: Conditional chains are evaluated from top to bottom.
A. n > 10 && n < 20 B. n == 10 || n == 20 C. n <= 10 && n >= 20 D. n < 10 || n > 20
Correct Answer: D. n < 10 || n > 20
Explanation: A value outside the interval is either below 10 or above 20, so || connects the two possibilities.
Key Takeaway: Think in terms of the two disjoint ways a value can be outside a range.
Focus: Loops. Questions progress from direct concept recognition toward application and code reasoning.
Correct Answer: C. 4 [Q17-3]
Explanation: The loop starts at 0 and runs for i = 0, 1, 2, and 3. When i becomes 4, the condition i < 4 is false.
Key Takeaway: A zero-based loop with i < 4 visits four values.
A. enhanced if B. for C. while [Q18-3]
Focus: Methods. Questions progress from direct concept recognition toward application and code reasoning.
A. static int doubleValue(int n) B. static void doubleValue(int n) C. int doubleValue() D. static integer doubleValue(number n)
Correct Answer: A. static int doubleValue(int n)
Explanation: The first declaration specifies int as the return type and one int parameter. void means no return value, and the other forms use incompatible syntax or omit the parameter.
Key Takeaway: A method signature's return type and parameter list describe what it produces and accepts.
A. It creates a new object without executing the constructor. B. It supplies a value to the caller and ends that method invocation. C. It changes a local variable into a class field. D. It repeats the method from its first line automatically.
Correct Answer: B. It supplies a value to the caller and ends that method invocation.
Explanation: In a non-void method, return supplies a value compatible with the declared return type and ends the current invocation.
Key Takeaway: return transfers a result back to the caller.
A. return 12; B. return; C. return false; D. return "done";
Correct Answer: B. return;
Explanation: A void method may use a bare return to exit early, but it cannot return a value.
Key Takeaway: void means the method does not return a value.
A. Its scope is limited to the relevant block in which it is declared. B. It automatically becomes a field shared by every object of the class. C. It remains available after the method invocation through the object.
D. It can be referenced from every class in the package.
Correct Answer: A. Its scope is limited to the relevant block in which it is declared.
Explanation: A local variable belongs to its declaring method/block scope. It is not automatically a field or globally accessible state.
Key Takeaway: Scope controls where a name can be referenced.
Focus: Arrays. Questions progress from direct concept recognition toward application and code reasoning.
Correct Answer: C. 5 [Q25-3]
Explanation: Java arrays are zero-indexed. An array of length 6 has valid indices 0 through 5.
Key Takeaway: The last index is length minus one.
B. undefined C. - D. null
Correct Answer: A. 0 [Q26-1]
Explanation: Java initializes int array elements to 0. null applies to reference types, not primitive int elements.
Key Takeaway: Java arrays receive default values when created.
A. for (int value : values) B. for (value int : values) C. foreach (int value in values) D. repeat (int value from values)
Correct Answer: A. for (int value : values)
Explanation: The enhanced-for syntax is for (type variable : arrayOrIterable). The first option follows Java's syntax.
Key Takeaway: Enhanced-for uses a colon between the element variable and the array/iterable.
Explanation: substring(begin, end) includes the begin index and excludes the end index, so indices 2, 3, and 4 are returned.
Key Takeaway: Java substring uses an inclusive start and exclusive end.
A. String concatenation can never create a new String object. B. Their contents are immutable after a String object has been created. C. Calling toUpperCase() changes the original String object in place. D. Every String variable always refers to a mutable character array.
Correct Answer: B. Their contents are immutable after a String object has been created.
Explanation: String is immutable: operations that appear to change text produce a new String value rather than modifying the original object.
Key Takeaway: Treat String operations as producing new values.
Focus: ArrayList. Questions progress from direct concept recognition toward application and code reasoning.
A. ArrayList names = new ArrayList<>(); B. ArrayList names = new String<>(); C. List names = new ArrayList(String); D. ArrayList names = ArrayList();
Correct Answer: A. ArrayList names = new ArrayList<>();
Explanation: The first declaration uses a generic type argument String and constructs an ArrayList with the diamond operator.
Key Takeaway: Generics express the element type stored in an ArrayList.
A. tasks.insertEnd("backup") B. tasks.pushTail("backup") C. tasks.appendLast("backup") D. tasks.add("backup")
Correct Answer: D. tasks.add("backup")
Explanation: ArrayList.add(element) appends the element to the end. The other method names are not standard ArrayList methods.
Key Takeaway: Use add(element) for ordinary append behavior.
B. The last index, which is 2 C. 4 [Q35-3] D. 2 [Q35-4]
Correct Answer: A. 3 [Q35-1]
Explanation: size() reports the number of elements, not the last index. With three elements, size is 3 and the last index is 2.
Key Takeaway: Collection size counts elements; indexes begin at zero.
A. queue.drop(2) B. queue.eraseIndex(2) C. queue.remove(2) D. queue.deleteAt(2)
Correct Answer: C. queue.remove(2)
Explanation: ArrayList.remove(int index) removes the element at the specified index. The other names are not standard ArrayList methods.
Key Takeaway: ArrayList removal can be performed by index with remove(int).
Focus: Classes & Objects. Questions progress from direct concept recognition toward application and code reasoning.
A. A blueprint describing state and behavior that objects can have. B. A compiler instruction that replaces every method call. C. A single object that can never have another instance. D. A package containing only primitive variables.
Correct Answer: A. A blueprint describing state and behavior that objects can have.
Explanation: A class defines fields, constructors, and methods that describe the state and behavior of its instances. Multiple objects can be created from one class.
Key Takeaway: Think of a class as a type definition and an object as an instance.
A. Sensor s = Sensor.createType; B. Sensor s = new Sensor(); C. new Sensor = s; D. object Sensor s();
Correct Answer: B. Sensor s = new Sensor();
Focus: Constructors. Questions progress from direct concept recognition toward application and code reasoning.
A. It has the same name as its class and has no declared return type. B. It must be static so it can run before object creation. C. It is declared with the keyword constructor before the class name. D. It must always be named initialize and return the object reference.
Correct Answer: A. It has the same name as its class and has no declared return type.
Explanation: A constructor has the same name as the class and does not declare a return type. It is invoked when an object is created.
Key Takeaway: Constructors initialize newly created objects.
A. The compiler converts every instance method into a constructor. B. The class can never be instantiated under any circumstances. C. Java can provide a default no-argument constructor, subject to the class's accessibility. D. Java automatically creates a constructor for every possible parameter list.
Correct Answer: C. Java can provide a default no-argument constructor, subject to the class's accessibility.
Explanation: If no constructor is explicitly declared, Java can supply a default no-argument constructor with the same accessibility as the class. Once any constructor is declared, that automatic constructor is not supplied.
Key Takeaway: Declaring a constructor changes whether the compiler supplies the default one.
A. To offer multiple initialization choices for different object-creation needs. B. To allow constructors to have unrelated class names. C. To convert instance methods into static utilities. D. To make every constructor execute simultaneously for one object.
Correct Answer: A. To offer multiple initialization choices for different object-creation needs.
Explanation: Multiple constructors with different parameter lists provide overloaded initialization paths.
Key Takeaway: Constructor overloading gives callers different ways to initialize an object.
A. It assigns the parameter named name to the current object's field named name. B. It creates a second object whose class is named name. C. It converts the field into a static variable.
D. It calls a superclass constructor named name.
Correct Answer: A. It assigns the parameter named name to the current object's field named name.
Explanation: this.name refers to the current object's field, while the unqualified name refers to the constructor parameter. The statement resolves the naming collision and assigns the parameter to the field.
Key Takeaway: this distinguishes an instance field from a parameter with the same name.
Focus: Encapsulation. Questions progress from direct concept recognition toward application and code reasoning.
A. Store the balance only in a local variable inside main. B. Declare the field final even when it must change frequently. C. Make the field public so every class can modify it freely. D. Keep the field private and expose controlled methods for reading or changing it.
Correct Answer: D. Keep the field private and expose controlled methods for reading or changing it.
Explanation: Encapsulation hides internal state and controls access through a public interface. A private field plus carefully designed methods is a common Java implementation.
Key Takeaway: Hide representation details and expose controlled behavior.
A. private means the field exists only while a constructor executes. B. private automatically converts the field into a constant. C. private prevents the JVM from allocating storage for the field. D. The private access modifier restricts direct member access to the declaring class.
Correct Answer: D. The private access modifier restricts direct member access to the declaring class.
Explanation: private limits direct access to the declaring class. Other classes must use permitted methods or other public/protected interfaces.
Key Takeaway: Access modifiers control who can directly use a member.
A. The class can reject or transform invalid state before storing it. B. Validation eliminates the need for constructors in every class. C. A setter automatically makes the field public to every caller. D. A setter prevents all runtime exceptions in the program.
Correct Answer: A. The class can reject or transform invalid state before storing it.
Explanation: A setter can enforce invariants such as nonnegative quantities before updating the object's internal state.
Key Takeaway: Controlled mutation lets a class protect its invariants.
C. The class definition itself is modified. D. The JVM automatically creates a third object to hold the change.
Correct Answer: B. The same object's field is changed, so observing it through a can show the new value.
Explanation: If a == b, both references identify one object. A field mutation through either reference changes that shared instance.
Key Takeaway: Multiple references can point to one object.
A. It refers to the class's static area only. B. It does not currently refer to an object instance. C. It refers to an object whose fields all contain zero. D. It is an object whose methods have been disabled.
Correct Answer: B. It does not currently refer to an object instance.
Explanation: null is the absence of an object reference. Dereferencing a null reference can cause NullPointerException.
Key Takeaway: null means no object is currently referenced.
Focus: Static Members. Questions progress from direct concept recognition toward application and code reasoning.
A. One class-level variable shared by the class's instances rather than a separate copy per object. B. A field that can only be accessed from constructors. C. A field that must contain a String literal. D. A local variable recreated every time an instance method runs.
Correct Answer: A. One class-level variable shared by the class's instances rather than a separate copy per object.
Explanation: A static field belongs to the class rather than to each individual instance, so there is one class-level storage location for the field.
Key Takeaway: static members belong to the class rather than a particular instance.
A. 7.MathBox.square() B. new MathBox.square(7) C. MathBox().square(7) D. MathBox.square(7)
Correct Answer: D. MathBox.square(7)
Explanation: A static method can be invoked through the class name, so MathBox.square(7) is the appropriate form.
Key Takeaway: Use the class name for ordinary static method calls.
A. Static methods execute only during compilation and therefore cannot read memory. B. Instance fields exist only inside constructors. C. A static method has no implicit current-instance reference. D. Java forbids static methods from reading any variables.
Correct Answer: C. A static method has no implicit current-instance reference.
Explanation: A static method is associated with the class and does not have an implicit this reference, so it cannot directly identify which object's instance field should be used.
Key Takeaway: Instance state requires a particular object.
A. Creating a new mutable value for every object. B. Representing a class-level constant whose value should not be reassigned. C. Allowing subclasses to override the constant at runtime. D. Storing temporary method-local input.
Correct Answer: B. Representing a class-level constant whose value should not be reassigned.
Explanation: A static final field is commonly used for a constant shared at class level. final prevents reassignment of the field after initialization.
Key Takeaway: static final is a common pattern for named constants.
Focus: Inheritance. Questions progress from direct concept recognition toward application and code reasoning.
A. Sedan can inherit from any number of unrelated classes. B. Sedan is a subclass that inherits accessible members and behavior from Vehicle. C. Sedan and Vehicle become unrelated classes with shared source text. D. Vehicle is automatically converted into an interface named Sedan.
Correct Answer: B. Sedan is a subclass that inherits accessible members and behavior from Vehicle.
Explanation: extends establishes a superclass/subclass relationship. A Sedan object is a Vehicle as well, subject to Java's inheritance rules.
Key Takeaway: extends creates a class inheritance relationship.
A. base B. up