Which statement correctly distinguishes a Java class from a Java object?
Using Java Objects, Classes, and Strings Online Quiz Questions
Use this free practice quiz with 20 questions to review Using Java Objects, Classes, and Strings, test your knowledge, and prepare for your next test or exam.
True or false: Declaring String text; creates a new String object.
- A
True
- B
False
What is printed by this code?
StringBuilder a = new StringBuilder("Hi");StringBuilder b = a;b.append("!");System.out.println(a);System.out.println(b);
- A
aprintsHiandbprintsHi!because assignment copies the object. - B
aprintsHi!andbprintsHibecauseappendchanges only the calling variable. - C
Both
aandbprintHi!because they are aliases for the same mutable object. - D
The code does not compile because two variables cannot refer to one
StringBuilder.
What value is produced by "computer".substring(1, 5)?
- A
ompu - B
ompur - C
comp - D
puter
Which pair correctly calls the two operations below?
String text = "hello";
Obtain the number of characters in
text.Find the larger of 12 and 20.
- A
String.length()andMath.max(12, 20) - B
length("hello")and20.max(12) - C
Math.length("hello")andmax.Math(12, 20) - D
text.length()andMath.max(12, 20)
Select all statements that are true after this code runs:
String word = "cat";word.toUpperCase();String upper = word.toUpperCase();
- A
After the code runs,
wordstill refers to the stringcat. - B
Calling
toUpperCase()changes the existingStringobject in place. - C
upperrefers to a string whose characters are uppercase. - D
wordanduppermust refer to the same object because both came fromword.
Select all statements that are true about these Java conversions and methods.
- A
Integer boxed = 7;uses autoboxing. - B
int primitive = boxed;uses unboxing. - C
int n = Integer.valueOf("7");necessarily returns anintdirectly. - D
int n = Integer.parseInt("7");stores a primitiveint.
True or false: For two String variables, the expression a == b is the reliable way to determine whether they contain the same characters.
- A
True
- B
False
True or false: If a class declares a constructor that takes an int, Java automatically supplies a no-parameter constructor as well.
- A
True
- B
False
What integer does "banana".indexOf("na") return? Enter the zero-based index as a decimal number.
Enter the Java String method name used to test whether two strings contain the same characters.
Complete both statements about Java constructors:
A constructor has the same name as its .
A constructor has no , not even void.
Complete both results:
"Java".length() returns ."computer".substring(4) returns .
Determine the exact two lines printed by this code and explain why the two variables have different final values:
String first = "AP";String second = first;second += " CSA";System.out.println(first);System.out.println(second);
Consider the statement Student learner = new Student("Maya", 10);. What does the variable learner contain after the statement executes?
- A
A class definition named learner
- B
A reference to a Student object initialized by a constructor call
- C
A primitive integer storing the value 10
- D
A static method belonging to Student
What value is returned by "computer".substring(3, 7)?
- A
comp - B
pute - C
puter - D
uter
Given String a = new String("Java"); and String b = new String("Java");, which result is correct for a == b and a.equals(b)?
- A
Both expressions evaluate to
true - B
Both expressions evaluate to
false - C
a == bis true, buta.equals(b)is false - D
a == bis false, buta.equals(b)is true
Which statement correctly classifies the method calls in the following code?
String word = "hello";int larger = Math.max(12, 20);int size = word.length();
- A
Math.max(12, 20)is a static call, andword.length()is an instance call - B
Both calls are static because both return values
- C
Both calls are instance calls because both use the dot operator
- D
Math.max(12, 20)is an instance call, andword.length()is a static call
What integer value is returned by Integer.parseInt("2026")?
What exact Java String method name returns the first index where a specified substring occurs, or -1 when the substring is absent?
Related study packs and tools
1. Computing, Culture, and Society
A progressive guide to how computing reshapes culture, economic life, public institutions, and individual opportunities, with frameworks for evaluating digital equity, bias, cybersecurity, encryption, and collective participation.
01. Introduction to Programming and Algorithmic Problem Solving
A medium-difficulty assessment of programming fundamentals, algorithmic problem solving, control flow, data structures, testing, debugging, complexity, and decidability. Questions progress from foundational understanding to applied reasoning.
3. Risks and Unintended Consequences
A 14-question quiz on the social, economic, privacy, informational, health, and environmental risks of computing innovations, including strategies for responsible design and oversight.
6. Cybersecurity and Digital Safety
A practical guide to recognizing cybersecurity threats, protecting accounts and devices, and responding safely when information or systems may be compromised.
7. Encryption, Privacy, and Trust
A guided introduction to how encryption, authentication, hashing, secure protocols, and key management establish confidentiality, integrity, privacy, and trust while creating practical and legal trade-offs.
08 — Discrete Mathematics for Computer Science
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
9. Evaluating the Social Impact of Computing
A practical guide to evaluating computing innovations by examining their benefits, risks, equity, security, participation, and long-term effects on people and communities.
12 — Foundations Capstone
A medium-difficulty quiz on integrating problem definition, representation, algorithms, complexity analysis, testing, correctness, ethical evaluation, and documentation in a computer science capstone.
Fault Tolerance and Redundant Systems
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
How the Internet Works
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
Packets, Links, and Network Performance
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
Parallel and Distributed Computing
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.