Java Programming Quiz: Fundamentals and Object-Oriented Concepts, Exams of Nursing

A comprehensive quiz covering fundamental java programming concepts, including data types, variables, operators, control flow, object-oriented programming principles, classes, objects, inheritance, polymorphism, and abstract classes. It includes multiple-choice questions with verified answers, providing a valuable resource for self-assessment and learning.

Typology: Exams

2023/2024

Available from 01/16/2025

Toperthetop
Toperthetop 🇬🇧

3

(6)

27K documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Comp 1406 questions with verified
answers to pass
Python uses dynamic typing. Java uses this:
Static typing
Dynamic typing
Speed typing
No typing - correct answer ✔✔Static typing
Java is an architecture independent language.
True
False - correct answer ✔✔True
Three steps to follow in order to create and run a Java program include:
Compiling, Writing Running
Writing, Running, Compiling
Writing, Compiling, Running
Writing, Running, Crying - correct answer ✔✔Writing, Compiling, Running
The line of code to print "Hello World" to the console in Java is:
Console.log("Hello World");
System.out.println("Hello World")
print("Hello World");
System.out.println("Hello World"); - correct answer ✔✔System.out.println("Hello World");
If you want to store a decimal number in a variable, the best Java primitive type to use would be:
int
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Java Programming Quiz: Fundamentals and Object-Oriented Concepts and more Exams Nursing in PDF only on Docsity!

Comp 1406 questions with verified

answers to pass

Python uses dynamic typing. Java uses this: Static typing Dynamic typing Speed typing No typing - correct answer ✔✔Static typing Java is an architecture independent language. True False - correct answer ✔✔True Three steps to follow in order to create and run a Java program include: Compiling, Writing Running Writing, Running, Compiling Writing, Compiling, Running Writing, Running, Crying - correct answer ✔✔Writing, Compiling, Running The line of code to print "Hello World" to the console in Java is: Console.log("Hello World"); System.out.println("Hello World") print("Hello World"); System.out.println("Hello World"); - correct answer ✔✔System.out.println("Hello World"); If you want to store a decimal number in a variable, the best Java primitive type to use would be: int

float char number - correct answer ✔✔float To define the state and behaviour of a new type within our Java program, we create a new: Question options: Object Constructor Class Address - correct answer ✔✔Class Another word for an instance variable is: Question options: Object Immediate variable Static variable Attribute - correct answer ✔✔Attribute You can only run/execute classes that contain: Question options: At least one static method A main method At least one attribute A toString method - correct answer ✔✔A main method The following process involves allocating memory for a new object: Question options: Declaration Instantiation

It depends on how many objects are created Static variables don't exist, only static methods - correct answer ✔✔One A static method can access/modify the attributes of a class: Question options: True False - correct answer ✔✔False If the code someObject.someAttribute causes a NullPointerException, then: Question options: someAttribute must be null someObject must be null Either someObject or someAttribute could be null It is impossible to tell - correct answer ✔✔someObject must be null The signature of a method includes: Question options: Only the method name The method name and the return type of the method The method name and order/type of the method attributes The method name, return type, and order/type of the method attributes - correct answer ✔✔The method name and order/type of the method attributes Which of the following is NOT a valid access modifier in Java: Question options: private public protected All of the above are valid. - correct answer ✔✔All of the above are valid.

Within a class, the private access modifier can be used to: Question options: Prevent modification of attributes by other classes Prevent the calling of methods by other classes Both of the above are true None of the above is true - correct answer ✔✔Both of the above are true The private access modifier can be used for instance variables, but cannot be used for static variables. Question options: True False - correct answer ✔✔False Which of the following is NOT an advantage of proper encapsulation? Question options: Encapsulated code uses less memory when executed Encapsulation provides a more abstract view of classes, which makes them easier to work with Encapsulation helps to enforce constraints on attributes within a class All of the above are advantages of proper encapsulation - correct answer ✔✔Encapsulated code uses less memory when executed Which of the following is NOT typically part of a get method: Question options: The public access modifier A non-void return type An input argument All of the above are typically part of a get method - correct answer ✔✔An input argument Which of the following is NOT typically part of a set method:

False - correct answer ✔✔False Assume class A is a subclass of class B. Which of the following is true? A inherits all of the public attributes of B B inherits all of the public attributes of A Both of the above are true None of the above are true - correct answer ✔✔A inherits all of the public attributes of B Assume class A is a subclass of class B. What keyword can be used on the first line of A's constructor in order to call the constructor of B? B parent super inherit - correct answer ✔✔super Method overriding involves: Changing the return type of an existing method Using the public access modifier to replace an inherited private access method Having more than one method with the same name, but different argument types Modifying inherited method behaviour by providing a different implementation within a subclass - correct answer ✔✔Modifying inherited method behaviour by providing a different implementation within a subclass Which of the following is true about an abstract class? The class cannot have any attributes The class cannot have any method implementations Instances of the class cannot be created All of the above are true. - correct answer ✔✔Instances of the class cannot be created Which of the following is true about interfaces?

Interfaces do not have any attributes Interfaces only have public methods Interfaces do not have constructors All of the above are true - correct answer ✔✔All of the above are true Given the class hierarchy within the image and the code "BankAccount b = new SavingsAccount();", which of the following is true: The variable b points to a BankAccount object The variable b points to a SavingsAccount object The variable b could point either to a BankAccount object or SavingsAccount object The code will not compile. Look at diagram if necessary quiz # 5 - correct answer ✔✔The variable b points to a SavingsAccount object Given the class hierarchy within the image, would the following line of code be valid? Insurable i = new Car(); True False Diagram on quiz # 5 - correct answer ✔✔True Given the class hierarchy within the image, would the following line of code be valid? Insurable i = new Person(); True False Diagram on quiz # 5 - correct answer ✔✔True

Implementations of the List ADT, such as ArrayList, allow us to manipulate the collection's data using convenient method names (e.g., add, remove, get) rather than several specific operations. This is an example of which principle of OOP? Abstraction Encapsulation Inheritance Polymorphism - correct answer ✔✔Abstraction If we write general code for the List ADT (i.e., the interface), we can easily swap between different implementations by instantiating different object types (i.e., an ArrayList or a Linkedlist). This is an example of which principle of OOP? Abstraction Encapsulation Inheritance Polymorphism - correct answer ✔✔Polymorphism Many of the Java Collections classes support automatic sorting using the Comparable interface. The fact that pre-written sorting code can be applied to any class that implements the Comparable interface is an example of which principle of OOP? Abstraction Encapsulation Inheritance Polymorphism - correct answer ✔✔Polymorphism Attempting to remove an item from a list while iterating over that list using a 'for each' loop will likely result in the following type of exception: ConcurrentModificationException InvalidDataException InvalidListRemovalException NullPointerException - correct answer ✔✔ConcurrentModificationException

The Queue ADT operates on data using which principle? First-in First-out Last-in First-Out All-in All-Out None of the above. - correct answer ✔✔First-in First-out The Stack ADT operates on data using which principle? First-in First-out Last-in First-Out All-in All-Out None of the above. - correct answer ✔✔Last-in First-Out Assume we are implementing the Comparable interface within the BankAccount class. We want to have the accounts sorted from highest to lowest balance, where balance is an integer value. The proper comparison would be (note: assume 'other' is the input argument to the compareTo method): return other.balance + this.balance; return this.balance + other.balance; return other.balance - this.balance; return this.balance - other.balance; - correct answer ✔✔return other.balance - this.balance; Assume you want to store the contents of the English dictionary within your program. You will need to look up the definition for any given word. The best data structure for this problem is most likely: ArrayList LinkedList HashSet HashMap - correct answer ✔✔HashMap There is not 'set' method for HashMaps. This is because:

Exception history Exception queue Stack trace - correct answer ✔✔Stack trace Within Java, files are represented as: Fountains Ponds Streams Oceans - correct answer ✔✔Streams Which general classes represent the base for classes used for reading and writing binary data within Java? InputStream and OutputStream Reader and Writer BinaryIn and BinaryOut None of the above. - correct answer ✔✔InputStream and OutputStream The process of adding to a file, rather than erasing the contents before re-writing, is referred to as: Appending Binary output Re-saving Underwriting - correct answer ✔✔Appending The DataOutputStream class makes use of a FileOutputStream object to perform the writing of bytes to a file. DataOutputStream is therefore referred to as a ____ class. Binary Dependent Useless Wrapper - correct answer ✔✔Wrapper

In order to save objects of a class to a file using the ObjectOutputStream, that class must implement this interface: Encodable Serializable Writable No interface is required. - correct answer ✔✔Serializable The part of the program that contains the 'business logic' of the application is often referred to as the: Graphical user interface Model Non-graphical user interface SQL Database - correct answer ✔✔Model The JavaFX class that will be the base for all of our window applications is called: Application FXApplication GUIApplication WindowApplication - correct answer ✔✔Application Any object with a visual representation that is placed on a window and usually allows the user to interact with it is called a: Button Graphical User Interface Window component None of the above. - correct answer ✔✔Window component The most basic and common container class in JavaFX is called: Box

The controller class in a JavaFX MVC application is most likely to extend which class? Application GUIApplication JavaFXControl Pane - correct answer ✔✔Application The view class in a JavaFX MVC application is most likely to extend which class? Application GUIApplication JavaFXControl Pane - correct answer ✔✔Pane This component of an MVC application typically has no attributes referencing either of the other two components: Model View Controller None of the above. - correct answer ✔✔Model This component of an MVC application typically has all of the event handlers: Model View Controller None of the above. - correct answer ✔✔Controller An indirectly recursive method is one that: Does not call itself but does call another directly recursive method Is sometimes recursive and sometimes not Uses the technique of 'sideways recursion'

Uses sleight of hand - correct answer ✔✔Does not call itself but does call another directly recursive method Each binary tree node has at most ___ parent node(s) and at most ___ child node(s). 1, 1 1, 2 2, 1 2, 2 - correct answer ✔✔1, 2 A binary tree node with no children is referred to as a _________. Branch Leaf Root Treebeard - correct answer ✔✔Leaf A recursive method that alters the data structure that it is applied to is referred to as: Destructive Non-destructive Non-serializable Serializable - correct answer ✔✔Destructive