Java Coding Questions
Quiz
•
Computers
•
University
•
Practice Problem
•
Hard
karthi jegadeesan
Used 6+ times
FREE Resource
Enhance your content in a minute
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Given the following class, what’s the output when creating a book with no parameters?
java
CopyEdit
class Book { String title; Book() { this("Untitled"); System.out.println("Default constructor called"); } Book(String title) { this.title = title; System.out.println("Title constructor called: " + title); } }
java
CopyEdit
Book b = new Book();
Only “Default constructor called”
Only “Title constructor called: Untitled”
Both lines, in order
Compilation error
2.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
You want to store a list of books borrowed by a user. Which of the following is the most appropriate collection?
A. HashSet<Book>
B. ArrayList<Book>
C. TreeMap<Book>
D. Vector<Book>
3.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
When a user tries to borrow a book that’s not available, a BookNotAvailableException should be thrown. Which is the correct way to define and throw a custom exception?
A. throw new Exception("Not available");
B. class BookNotAvailableException extends RuntimeException
C. throw new BookNotAvailableException(); after defining the class extending Exception
D. All of the above are correct
4.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
What will happen when the following code is executed?
int[] arr = {10, 20, 30}; for (int i = 0; i <= arr.length; i++) { System.out.println(arr[i]); }
A. Prints all elements successfully
B. Compiles but throws ArrayIndexOutOfBoundsException at runtime
C. Compile-time error
D. Prints garbage values
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following lines will throw a NullPointerException?
String s = null;
A. if (s == null)
B. if ("test".equals(s))
C. if (s.equals("test"))
D. System.out.println(s)
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code?
boolean flag = false; if (flag = true) { System.out.println("Flag is true"); } else { System.out.println("Flag is false"); }
A. Flag is true
B. Flag is false
C. Compile-time error
D. Runtime exception
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the result of the code below?
public class Test { public static void main(String[] args) { return; System.out.println("This won't print"); } }
A. Code runs normally
B. Compilation error: unreachable code
C. Prints the statement
D. Runtime exception
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
20 questions
DreamWeaver CS6
Quiz
•
University
15 questions
ARRAYS AND FUNCTIONS
Quiz
•
University
16 questions
Digital etiquette
Quiz
•
KG - Professional Dev...
15 questions
Round 2 Debug-The-Code
Quiz
•
University
20 questions
קלט פלט משתנים והוראות השמה
Quiz
•
7th Grade - University
15 questions
Administration Database
Quiz
•
University - Professi...
20 questions
Hashing
Quiz
•
University
20 questions
C - Structures
Quiz
•
University
Popular Resources on Wayground
10 questions
Honoring the Significance of Veterans Day
Interactive video
•
6th - 10th Grade
9 questions
FOREST Community of Caring
Lesson
•
1st - 5th Grade
10 questions
Exploring Veterans Day: Facts and Celebrations for Kids
Interactive video
•
6th - 10th Grade
19 questions
Veterans Day
Quiz
•
5th Grade
14 questions
General Technology Use Quiz
Quiz
•
8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Circuits, Light Energy, and Forces
Quiz
•
5th Grade
19 questions
Thanksgiving Trivia
Quiz
•
6th Grade
Discover more resources for Computers
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)
Quiz
•
8th Grade - University
7 questions
Force and Motion
Interactive video
•
4th Grade - University
9 questions
Principles of the United States Constitution
Interactive video
•
University
18 questions
Realidades 2 2A reflexivos
Quiz
•
7th Grade - University
10 questions
Dichotomous Key
Quiz
•
KG - University
25 questions
Integer Operations
Quiz
•
KG - University
7 questions
What Is Narrative Writing?
Interactive video
•
4th Grade - University
20 questions
SER vs ESTAR
Quiz
•
7th Grade - University
