SlideShare a Scribd company logo
Java SE 17 Study Guide
Chapter 1
Bill Herman
WilliamRobertHerman@Gmail.com
Question 1
Which of the following are legal entry point
methods that can be run from the command
line? (Choose all that apply)
private static void main(String[] args)
public static final main(String[] args)
public void main(String[] args)
public static final void main(String[] args)
public static void main(String[] args)
public static main(String[] args)
Answer 1
Which of the following are legal entry point
methods that can be run from the command
line? (Choose all that apply)
private static void main(String[] args)
public static final main(String[] args)
public void main(String[] args)
public static final void main(String[] args)
public static void main(String[] args)
public static main(String[] args)
Comment: Final is optional
Question 2
What order of statements will
compile successfully?
class Rabbit {} import java.util.*;
package animals;
import java.util.*; package
animals; class Rabbit {}
package animals; import
java.util.*; class Rabbit {}
import java.util.*; class Rabbit {}
package animals; class Rabbit {}
class Rabbit {} package animals;
None of the above

Recommended for you

1
11
1

The document contains 20 multiple choice questions about Java programming concepts such as threads, assertions, references, operators, and more. For each question, the stem presents a code snippet, output, or statement and asks which answer choice is true. The explanations provided give detailed reasoning for the correct answers and why the incorrect choices are wrong based on Java specifications.

Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC

This workshop is about testing the right way. Get a clear view on how to test your code in an efficient and useful way! This first testing-related workshop is about all aspects of unit testing. Integration testing and TDD will have their own dedicated workshops.

mockitounit testingjava
Java performance
Java performanceJava performance
Java performance

The document discusses Java string performance and summarizes some key findings: 1) The String class is one of the most commonly used in Java projects and consumes significant memory. The most common string operations are concatenation and comparison. 2) For concatenation, StringBuilder.append is generally faster than String.concat. String concatenation at compile-time is the most efficient. 3) For comparison, String.compareTo is the fastest method, followed by String.equals and String.equalsIgnoreCase, with String.intern being the slowest but most memory-efficient for duplicate strings.

stringequalsstringbuilder
Answer 2
What order of statements will compile
successfully?
class Rabbit {} import java.util.*;
package animals;
import java.util.*; package animals;
class Rabbit {}
package animals; import java.util.*;
class Rabbit {}
import java.util.*; class Rabbit {}
package animals; class Rabbit {}
class Rabbit {} package animals;
None of the above
Comment: package & import optional:
package then import then class
Question 3
Which of the following are true?
(Choose all that apply.)
public class Bunny {
public static void main(String[] x)
{
Bunny bun = new Bunny();
}
}
Bunny is a class.
bun is a class.
main is a class.
Bunny is a reference to an object.
bun is a reference to an object.
main is a reference to an object.
The main () method doesn't run
because the parameter name is
incorrect.
Question 3
Which of the following are true?
(Choose all that apply.)
public class Bunny {
public static void main(String[] x)
{
Bunny bun = new Bunny();
}
}
Bunny is a class.
bun is a class.
main is a class.
Bunny is a reference to an object.
bun is a reference to an object.
main is a reference to an object.
The main () method doesn't run
because the parameter name is
incorrect.
Question 4
Which of the following are valid
Java identifiers? (Choose all that
apply.)
_
_helloWorld$
true
java.lang
Public
1980_s
_Q2_

Recommended for you

Core java
Core javaCore java
Core java

This document contains 20 multiple choice questions about Java programming concepts such as classes, constructors, exceptions, arrays, inheritance, and more. The questions cover topics like output of code snippets, default values of array elements, reserved keywords, valid code constructs, and true/false statements about classes, wrappers, and exceptions.

cdac examinationcdacccee 2014
Java practical
Java practicalJava practical
Java practical

The document provides code examples for several Java programming concepts: 1. A program that takes command line arguments, calculates the sum and average of the numbers passed, and displays the results. 2. A Student class with member functions to read and display student details like name and age. 3. A Square class with data members for length, area, and perimeter, and member functions to read, compute values, and display details. The document contains 10 additional examples covering topics like inheritance, packages, exceptions, threads, and GUI programming.

any body
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper

The document contains a list of 40 Java interview questions related to core Java, servlets, and JSP. The questions cover topics such as default array values, declaring and initializing arrays, Java keywords, if/else conditions, switch statements, loops, strings, wrappers, methods, threads, JDBC, servlet scopes, servlet lifecycle methods, differences between servlets and JSPs, implicit objects in JSP, and JSP directives.

fnt software solutionsfnt software solutions pvt ltd
Answer 4
Which of the following are valid
Java identifiers? (Choose all that
apply.)
_ (single underscore not allowed)
_helloWorld$
true (reserved word)
java.lang (contains .)
Public
1980_s (starts with number)
_Q2_
Question 5
Which statements about the following program are correct?
(Choose all that apply.)
2: public class Bear {
3: private Bear pandaBear;
4: private void roar(Bear b) {
5: System.out.println("Roar!");
6: pandaBear = b;
7: }
8: public static void main(String[] args) {
9: Bear brownBear = new Bear();
10: Bear polarBear = new Bear();
11: brownBear.roar(polarBear);
12: polarBear = null;
13: brownBear = null;
14: System.gc(); } }
The object created on line 9 is eligible for garbage collection
after line 13.
The object created on line 9 is eligible for garbage collection
after line 14.
The object created on line 10 is eligible for garbage collection
after line 12.
The object created on line 10 is eligible for garbage collection
after line 13.
Garbage collection is guaranteed to run.
Garbage collection might or might not run.
The code does not compile.
Answer 5
Which statements about the following program are correct?
(Choose all that apply.)
2: public class Bear {
3: private Bear pandaBear;
4: private void roar(Bear b) {
5: System.out.println("Roar!");
6: pandaBear = b;
7: }
8: public static void main(String[] args) {
9: Bear brownBear = new Bear();
10: Bear polarBear = new Bear();
11: brownBear.roar(polarBear);
12: polarBear = null;
13: brownBear = null;
14: System.gc(); } }
The object created on line 9 is eligible for garbage collection
after line 13. (set to null)
The object created on line 9 is eligible for garbage collection
after line 14. (new Bear())
The object created on line 10 is eligible for garbage collection
after line 12. (new Bear())
The object created on line 10 is eligible for garbage collection
after line 13. (set to null)
Garbage collection is guaranteed to run.
Garbage collection might or might not run.
The code does not compile.
Question 6
Assuming the following class compiles, how
many variables defined in the class or method
are in scope on the line marked on line 14?
1: public class Camel {
2: { int hairs = 3_000_0; }
3: long water, air=2;
4: boolean twoHumps = true;
5: public void spit(float distance) {
6: var path = "";
7: { double teeth = 32 + distance++; }
8: while(water > 0) { int age = twoHumps
? i : 2; Short i=-i; for(i=0; i<10; i++) {var Private
= 2; { // SCOPE } } }
2
3
4
5
6
7
None of the above

Recommended for you

Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers

Questions on Java 8 Concurrency. It has answers and explanation too. This will be more useful OCPJP aspirants

oracle certificationocajpocjp
Java tut1
Java tut1Java tut1
Java tut1

- Java is a platform independent programming language that is similar to C++ in syntax but similar to Smalltalk in its object-oriented approach. It provides features like automatic memory management, security, and multi-threading capabilities. - Java code is compiled to bytecode that can run on any Java Virtual Machine (JVM). The JVM then interprets the bytecode and may perform just-in-time (JIT) compilation for improved performance. This allows Java programs to run on any platform with a JVM. - Java supports object-oriented programming principles like encapsulation, inheritance, and polymorphism. Classes can contain methods and instance variables. Methods can be called on objects to perform operations or retrieve data.

Java Tutorial
Java TutorialJava Tutorial
Java Tutorial

- Java is a platform independent programming language that is similar to C++ in syntax but similar to Smalltalk in its object-oriented approach. It provides features like automatic memory management, security, and multi-threading capabilities. - Java code is compiled to bytecode that can run on any Java Virtual Machine (JVM). Only depending on the JVM allows Java code to run on any hardware or operating system with a JVM. - Java supports object-oriented programming concepts like inheritance, polymorphism, and encapsulation. Classes can contain methods and instance variables to define objects.

javatutorial
Question 6
Assuming the following class compiles, how
many variables defined in the class or method
are in scope on the line marked at // SCOPE?
1: public class Camel {
2: { int hairs = 3_000_0; }
3: long water, air=2;
4: boolean twoHumps = true;
5: public void spit(float distance) {
6: var path = "";
7: { double teeth = 32 + distance++; }
8: while(water > 0) { int age = twoHumps
? i : 2; Short i=-i; for(i=0; i<10; i++) {var Private
= 2; { //
SCOPE } } }
2
3
4
5
6
7
None of the above
Question 7
Which are true about this code? (Choose all that
apply.)
public class KitchenSink {
private int numForks;
public static void main(String[] args) {
int numKnives;
System.out.print("""
"# forks = " + numForks +
" # knives = " + numKnives +
# cups = 0""");
}
}
The output includes: # forks = 0.
The output includes: # knives = 0.
The output includes: # cups = 0.
The output includes a blank line.
The output includes one or more lines that
begin with whitespace.
The code does not compile.
Answer 7
Which are true about this code? (Choose all that
apply.)
public class KitchenSink {
private int numForks;
public static void main(String[] args) {
int numKnives;
System.out.print("""
"# forks = " + numForks +
" # knives = " + numKnives +
# cups = 0""");
}
}
The output includes: # forks = 0.
The output includes: # knives = 0.
The output includes: # cups = 0.
The output includes a blank line.
The output includes one or more lines that
begin with whitespace.
The code does not compile.
Comment: forks and knives are never used
Question 8
Which of the following code
snippets about var compile
without issue when used in a
method? (Choose all that apply.)
var spring = null;
var fall = "leaves";
var evening = 2; evening = null;
var night = Integer.valueof(3);
var day = 1/0;
var winter = 12, cold;
var fall = 2, autumn = 2;
var morning = ""; morning = null;

Recommended for you

Java Tut1
Java Tut1Java Tut1
Java Tut1

Java allows writing code once that can run on any platform. It compiles to bytecode that runs on the Java Virtual Machine (JVM). Key features include automatic memory management, object-oriented design, platform independence, security, and multi-threading. Classes are defined in .java files and compiled to .class files. The JVM interprets bytecode and uses just-in-time compilation to improve performance.

javatutorialjava
Tutorial java
Tutorial javaTutorial java
Tutorial java

- Java is a platform independent programming language that is similar to C++ in syntax but similar to Smalltalk in its object-oriented approach. It provides features like automatic memory management, security, and multi-threading capabilities. - Java code is compiled to bytecode that can run on any Java Virtual Machine (JVM). Only depending on the JVM allows Java code to run on any hardware or operating system with a JVM. - Java supports object-oriented programming concepts like inheritance, polymorphism, and encapsulation. Classes can contain methods and instance variables. Methods perform actions and can return values.

javatutorialjava virtual machine
Finding bugs that matter with Findbugs
Finding bugs that matter with FindbugsFinding bugs that matter with Findbugs
Finding bugs that matter with Findbugs

FindBugs is a static analysis tool that looks for bugs in Java code based on predefined bug patterns. It analyzes code without executing it and flags issues related to correctness, bad practices, performance, security, and concurrency. Some common bug patterns it finds include null pointer dereferences, ignored return values from methods, and potential infinite recursive loops. The tool is useful for finding bugs early before testing or deployment. Google and other companies use FindBugs to analyze their Java codebases and have found and fixed hundreds of issues through this process.

javafindbugsbugs
Answer 8
Which of the following code
snippets about var compile
without issue when used in a
method? (Choose all that apply.)
var spring = null;
var fall = "leaves";
var evening = 2; evening = null;
var night = Integer.valueof(3);
var day = 1/0;
var winter = 12, cold;
var fall = 2, autumn = 2;
var morning = ""; morning = null;
Comment: var not allowed multi
Question 9
Which of the following are correct?
(Choose all that apply.)
An instance variable of type float
defaults to 0.
An instance variable of type char
defaults to null.
A local variable of type double defaults
to 0.0.
A local variable of type int defaults to
null.
A class variable of type String defaults
to null.
A class variable of type String defaults
to the empty string "".
None of the above.
Answer 9
Which of the following are correct?
(Choose all that apply.)
An instance variable of type float
defaults to 0.
An instance variable of type char
defaults to null.
A local variable of type double defaults
to 0.0.
A local variable of type int defaults to
null.
A class variable of type String defaults
to null.
A class variable of type String defaults
to the empty string "".
None of the above.
Question 10
Which of the following expressions,
when inserted independently into
the blank line, allow the code to
compile? (Choose all that apply.)
public void printMagicData() {
var magic =
___________________;
System.out.println (magic) ;
}
3_1
1_329_.0
3_13.0_
5_291._2
2_234.0_0
9___6
_1_3_5_0

Recommended for you

Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics

Esoft Metro Campus - Certificate in java basics (Template - Virtusa Corporate) Contents: Module 1 1.1 Introduction to Java Module 2 2.1 Getting Start Java Programming Language 2.2 Java Variables Java Objects Java Methods Module 3 3.1 Operators 3.2 Flow Control Module 4 4.1 Access Modifiers 4.2 Non Access Modifiers 4.3 Interfaces Module 5 5.1 Object Orientation Module 6 6.1 String 6.2 String Buffer and String Builder Classes 6.3 Scanner Module 7 7.1 Wrapper classes 7.2 Auto boxing Module 8 8.1 Basic Collection Framework Module 9 9.1 Java Exception

javaesoftcertificate in java basics
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan

The document describes a Java program to calculate parcel shipping charges based on weight. It begins with an initial charge of Rs. 15 for the first 1KG. Any additional weight is charged Rs. 8 for every 500g or fraction thereof. The program takes a weight in KGs as input, calculates the remaining weight after deducting 1KG, determines the charge for full 500g increments and any fractional part, and outputs the total charge.

Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 Quizzes

The document provides examples of common syntax errors encountered when compiling code in Java and short explanations of the errors. It then presents a quiz with questions about method signatures, including identifying the method name, return type, number of parameters, and how to call the method. Finally, it presents another quiz about Java concepts like classes, objects, subclasses, and comments.

Answer 10
Which of the following expressions,
when inserted independently into
the blank line, allow the code to
compile? (Choose all that apply.)
public void printMagicData() {
var magic =
___________________;
System.out.println (magic) ;
}
3_1
1_329_.0
3_13.0_
5_291._2
2_234.0_0
9___6
_1_3_5_0
Comment: _ is legal if not at the
beginning or end or next to “.”
Question 11
Given the following two class files, what is the
maximum number of imports that can be
removed and have the code still compile?
// Water.java
package aquarium;
public class Water { }
// Tank.java
package aquarium;
import java.lang.*; import java.lang.System;
import aquarium.Water; import aquarium.*;
public class Tank {
public void print(Water water) {
System.out.println(water); } }
0
1
2
3
4
Does not compile
Answer 11
Given the following two class files, what is the
maximum number of imports that can be
removed and have the code still compile?
// Water.java
package aquarium;
public class Water { }
// Tank.java
package aquarium;
import java.lang.*; import java.lang.System;
import aquarium.Water; import aquarium.*;
public class Tank {
public void print(Water water) {
System.out.println(water); } }
0
1
2
3
4
Does not compile
Comment: java.lang included as default.
Aquarium already imported.
Question 12
Which statements about the following class
are correct? (Choose all that apply.)
1: public class ClownFish {
2: int gills = 0, double weight=2;
3: { int fins = gills; }
4: void print(int length = 3) {
5: System.out.println(gills);
6: System.out.println(weight);
7: System.out.println(fins);
8: System.out.println(length);
9:} }
Line 2 generates a compiler error.
Line 3 generates a compiler error.
Line 4 generates a compiler error.
Line 7 generates a compiler error.
The code prints 0.
The code prints 2.0.
The code prints 2.
The code prints 3.

Recommended for you

Core java day1
Core java day1Core java day1
Core java day1

This begins your journey to java as a very beginner. Prerequisite of the audience is strong understanding of basic language fundamentals of C or C++ or C# .

java beginners
Java puzzles
Java puzzlesJava puzzles
Java puzzles

Some puzzles that i presented to my company. Most of these are taken from books or other presentations from josh bloch

javapuzzles
Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...
Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...
Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...

IN Dubai [WHATSAPP:Only (+971588192166**)] Abortion Pills For Sale In Dubai** UAE** Mifepristone and Misoprostol Tablets Available In Dubai** UAE CONTACT DR. SINDY Whatsapp +971588192166* We Have Abortion Pills / Cytotec Tablets /Mifegest Kit Available in Dubai** Sharjah** Abudhabi** Ajman** Alain** Fujairah** Ras Al Khaimah** Umm Al Quwain** UAE** Buy cytotec in Dubai +971588192166* '''Abortion Pills near me DUBAI | ABU DHABI|UAE. Price of Misoprostol** Cytotec” +971588192166* ' Dr.SINDY ''BUY ABORTION PILLS MIFEGEST KIT** MISOPROSTOL** CYTOTEC PILLS IN DUBAI** ABU DHABI**UAE'' Contact me now via What's App… abortion pills in dubai Mtp-Kit Prices abortion pills available in dubai/abortion pills for sale in dubai/abortion pills in uae/cytotec dubai/abortion pills in abu dhabi/abortion pills available in abu dhabi/abortion tablets in uae … abortion Pills Cytotec also available Oman Qatar Doha Saudi Arabia Bahrain Above all** Cytotec Abortion Pills are Available In Dubai / UAE** you will be very happy to do abortion in Dubai we are providing cytotec 200mg abortion pills in Dubai** UAE. Medication abortion offers an alternative to Surgical Abortion for women in the early weeks of pregnancy. We only offer abortion pills from 1 week-6 Months. We then advise you to use surgery if it's beyond 6 months. Our Abu Dhabi** Ajman** Al Ain** Dubai** Fujairah** Ras Al Khaimah (RAK)** Sharjah** Umm Al Quwain (UAQ) United Arab Emirates Abortion Clinic provides the safest and most advanced techniques for providing non-surgical** medical and surgical abortion methods for early through late second trimester** including the Abortion By Pill Procedure (RU 486** Mifeprex** Mifepristone** early options French Abortion Pill)** Tamoxifen** Methotrexate and Cytotec (Misoprostol). The Abu Dhabi** United Arab Emirates Abortion Clinic performs Same Day Abortion Procedure using medications that are taken on the first day of the office visit and will cause the abortion to occur generally within 4 to 6 hours (as early as 30 minutes) for patients who are 3 to 12 weeks pregnant. When Mifepristone and Misoprostol are used** 50% of patients complete in 4 to 6 hours; 75% to 80% in 12 hours; and 90% in 24 hours. We use a regimen that allows for completion without the need for surgery 99% of the time. All advanced second trimester and late term pregnancies at our Tampa clinic (17 to 24 weeks or greater) can be completed within 24 hours or less 99% of the time without the need for surgery. The procedure is completed with minimal to no complications. Our Women's Health Center located in Abu Dhabi** United Arab Emirates** uses the latest medications for medical abortions (RU-486** Mifeprex** Mifegyne** Mifepristone** early options French abortion pill)** Methotrexate and Cytotec (Misoprostol). The safety standards of our Abu Dhabi** United Arab Emirates Abortion Doctors remain unparalleled. They consistently maintain the lowest complication rates throughout the nation. Our

Answer 12
Which statements about the following class
are correct? (Choose all that apply.)
1: public class ClownFish {
2: int gills = 0, double weight=2;
3: { int fins = gills; }
4: void print(int length = 3) {
5: System.out.println(gills);
6: System.out.println(weight);
7: System.out.println(fins);
8: System.out.println(length);
9:} }
Line 2 generates a compiler error.
Line 3 generates a compiler error.
Line 4 generates a compiler error.
Line 7 generates a compiler error.
The code prints 0.
The code prints 2.0.
The code prints 2.
The code prints 3.
Comment: Line 2 is invalid because
different types and comma instead of semi-
colon. Line 4 is not a valid parameter
signature.
Question 13
Given the following classes, which of the
following snippets can independently be
inserted in place of INSERT IMPORTS HERE
and have the code compile? (Choose all
that apply.)
package aquarium;
public class Water { boolean salty = false; }
package aquarium.jellies;
public class Water { boolean salty = true;}
package employee;
INSERT IMPORTS HERE
public class WaterFiller { Water water; }
import aquarium.*;
import aquarium.Water; import
aquarium.jellies.*;
import aquarium.*; import
aquarium.jellies.Water;
import aquarium.*; import
aquarium.jellies.*;
import aquarium.Water; import
aquarium.jellies.Water;
None of these imports can make the code
compile.
Answer 13
Given the following classes, which of the
following snippets can independently be
inserted in place of INSERT IMPORTS HERE
and have the code compile? (Choose all
that apply.)
package aquarium;
public class Water { boolean salty = false; }
package aquarium.jellies;
public class Water { boolean salty = true;}
package employee;
INSERT IMPORTS HERE
public class WaterFiller { Water water; }
import aquarium.*;
import aquarium.Water; import
aquarium.jellies.*;
import aquarium.*; import
aquarium.jellies.Water;
import aquarium.*; import
aquarium.jellies.*;
import aquarium.Water; import
aquarium.jellies.Water;
None of these imports can make the code
compile.
Comment: Duplicate class name (Water)
not selected correctly.
Question 14
Which of the following statements
about the code snippet are
true?(Choose all that apply.)
3: short numPets = 5L;
4: int numGrains = 2.0;
5: String name = "Scruffy";
6: int d = numPets.length();
7: int e = numGrains.length;
8: int f = name.length();
Line 3 generates a compiler error.
Line 4 generates a compiler error.
Line 5 generates a compiler error.
Line 6 generates a compiler error.
Line 7 generates a compiler error.
Line 8 generates a compiler error.

Recommended for you

CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.

CViewSurvey is a SaaS-based Web & Mobile application that provides digital transformation to traditional paper surveys and feedback for customer & employee experience, field & market research that helps you evaluate your customer's as well as employee's loyalty. With our unique C.A.A.G. Collect, Analysis, Act & Grow approach; business & industry’s can create customized surveys on web, publish on app to collect unlimited response & review AI backed real-time data analytics on mobile & tablets anytime, anywhere. Data collected when offline is securely stored in the device, which syncs to the cloud server when connected to any network.

saasapplicationdigital marketing
introduction of Ansys software and basic and advance knowledge of modelling s...
introduction of Ansys software and basic and advance knowledge of modelling s...introduction of Ansys software and basic and advance knowledge of modelling s...
introduction of Ansys software and basic and advance knowledge of modelling s...

Ansys Mechanical enables you to solve complex structural engineering problems and make better, faster design decisions. With the finite element analysis (FEA) solvers available in the suite, you can customize and automate solutions for your structural mechanics problems and parameterize them to analyze multiple design scenarios. Ansys Mechanical is a dynamic tool that has a complete range of analysis tools.

mechanical engineeringmodelling software3d modelling software
React Native vs Flutter - SSTech System
React Native vs Flutter  - SSTech SystemReact Native vs Flutter  - SSTech System
React Native vs Flutter - SSTech System

Your project needs and long-term objectives will ultimately choose which of React Native and Flutter to use. For applications using JavaScript and current web technologies in particular, React Native is a mature and trustworthy choice. For projects that value performance and customizability across many platforms, Flutter, on the other hand, provides outstanding performance and a unified UI development experience.

mobile app developmentreact native vs fluttermobile app design
Answer 14
Which of the following statements
about the code snippet are
true?(Choose all that apply.)
3: short numPets = 5L;
4: int numGrains = 2.0;
5: String name = "Scruffy";
6: int d = numPets.length();
7: int e = numGrains.length;
8: int f = name.length();
Line 3 generates a compiler error.
Line 4 generates a compiler error.
Line 5 generates a compiler error.
Line 6 generates a compiler error.
Line 7 generates a compiler error.
Line 8 generates a compiler error.
Question 15
Which of the following statements about
garbage collection are correct? (Choose all that
apply.)
Calling System.gc( ) is guaranteed to free up
memory by destroying objects eligible for
garbage collection.
Garbage collection runs on a set schedule.
Garbage collection allows the JVM to reclaim
memory for other objects.
Garbage collection runs when your program has
used up half the available memory.
An object may be eligible for garbage collection
but never removed from the heap.
An object is eligible for garbage collection once
no references to it are accessible in the
program.
Marking a variable final means its associated
object will never be garbage collected.
Answer 15
Which of the following statements about
garbage collection are correct? (Choose all that
apply.)
Calling System.gc( ) is guaranteed to free up
memory by destroying objects eligible for
garbage collection.
Garbage collection runs on a set schedule.
Garbage collection allows the JVM to reclaim
memory for other objects.
Garbage collection runs when your program has
used up half the available memory.
An object may be eligible for garbage collection
but never removed from the heap.
An object is eligible for garbage collection once
no references to it are accessible in the
program.
Marking a variable final means its associated
object will never be garbage collected.
Question 16
Which are true about this code?
(Choose all that apply.)
var blocky = """
squirrel s
pigeon 
termite""";
System.out.print(blocky);
It outputs two lines.
It outputs three lines.
It outputs four lines.
There is one line with trailing
whitespace.
There are two lines with trailing
whitespace.
If we indented each line five
characters, it would change the
output.

Recommended for you

Development of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML TechnologiesDevelopment of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML Technologies

A captivating AI chatbot PowerPoint presentation is made with a striking backdrop in order to attract a wider audience. Select this template featuring several AI chatbot visuals to boost audience engagement and spontaneity. With the aid of this multi-colored template, you may make a compelling presentation and get extra bonuses. To easily elucidate your ideas, choose a typeface with vibrant colors. You can include your data regarding utilizing the chatbot methodology to the remaining half of the template.

chatbot ppt
Leading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptxLeading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptx

Taskroup is the leading project management tool designed to streamline your workflow and boost productivity. Try it now! https://taskroup.com/about/

leading project management
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...

AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introduction.pdf

awscloudpractitioner
Answer 16
Which are true about this code?
(Choose all that apply.)
var blocky = """
squirrel s
pigeon
termite""";
System.out.print(blocky);
It outputs two lines.
It outputs three lines.
It outputs four lines.
There is one line with trailing
whitespace.
There are two lines with trailing
whitespace.
If we indented each line five
characters, it would change the
output.
Comment: s = keep white space, 
means remove line break
Question 17
What lines are printed by the following program?
(Choose all that apply.)
1: public class WaterBottle {
2: private String brand;
3: private boolean empty;
4: public static float code;
5: public static void main(String[] args) {
6: WaterBottle wb = new WaterBottle();
7: System.out.println("Empty = " + wb.empty);
8: System.out.println("Brand = " + wb.brand);
9: System.out.println("Code = " + code);
10: } }
Line 8 generates a compiler error.
Line 9 generates a compiler error.
Empty =
Empty = false
Brand =
Brand = null
Code = 0.0
Code = 0f
Answer 17
What lines are printed by the following program?
(Choose all that apply.)
1: public class WaterBottle {
2: private String brand;
3: private boolean empty;
4: public static float code;
5: public static void main(String[] args) {
6: WaterBottle wb = new WaterBottle();
7: System.out.println("Empty = " + wb.empty);
8: System.out.println("Brand = " + wb.brand);
9: System.out.println("Code = " + code);
10: } }
Line 8 generates a compiler error.
Line 9 generates a compiler error.
Empty =
Empty = false
Brand =
Brand = null
Code = 0.0
Code = 0f
Comment: printed values are defaults
Question 18
Which of the following statements
about var are true? (Choose all that
apply.)
A var can be used as a constructor
parameter.
The type of a var is known at compile
time.
A var cannot be used as an instance
variable.
A var can be used in a multiple variable
assignment statement.
The value of a var cannot change at
runtime.
The type of a var cannot change at
runtime.
The word var is a reserved word in Java.

Recommended for you

ANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdfANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdf

Ansys Mechanical enables you to solve complex structural engineering problems and make better, faster design decisions. With the finite element analysis (FEA) solvers available in the suite, you can customize and automate solutions for your structural mechanics problems and parameterize them to analyze multiple design scenarios. Ansys Mechanical is a dynamic tool that has a complete range of analysis tools.

mechanical engineeringsoftware3d software
MVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptxMVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptx

An MVP (Minimum Viable Product) mobile application is a streamlined version of a mobile app that includes only the core features necessary to address the primary needs of its users. The purpose of an MVP is to validate the app concept with minimal resources, gather user feedback, and identify any areas for improvement before investing in a full-scale development. This approach allows businesses to quickly launch their app, test its market viability, and make data-driven decisions for future enhancements, ensuring a higher likelihood of success and user satisfaction.

mvp developmentmvp software developmentmvp mobile application
WEBINAR SLIDES: CCX for Cloud Service Providers
WEBINAR SLIDES: CCX for Cloud Service ProvidersWEBINAR SLIDES: CCX for Cloud Service Providers
WEBINAR SLIDES: CCX for Cloud Service Providers

Browse the slides from our recent webinar hosted by Divine Odazie, our tech evangelist.

cloudccxcloud services
Answer 18
Which of the following statements
about var are true? (Choose all that
apply.)
A var can be used as a constructor
parameter.
The type of a var is known at compile
time.
A var cannot be used as an instance
variable.
A var can be used in a multiple variable
assignment statement.
The value of a var cannot change at
runtime.
The type of a var cannot change at
runtime.
The word var is a reserved word in Java.
Question 19
Which are true about the
following code? (Choose all that
apply.)
var num1 =
Long.parseLong(“100");
var num2 = Long.valueof("100");
System.out.println(Long.max(num
1, num2)) ;
The output is 100.
The output is 200.
The code does not compile.
num1 is a primitive.
num2 is a primitive.
Answer 19
Which are true about the
following code? (Choose all that
apply.)
var num1 =
Long.parseLong(“100");
var num2 = Long.valueof("100");
System.out.println(Long.max(num
1, num2)) ;
The output is 100.
The output is 200.
The code does not compile.
num1 is a primitive.
num2 is a primitive.
Question 20
Which statements about the following class are
correct? (Choose all that apply.)
public class PoliceBox {
String color; long age;
public void PoliceBox() { color = "blue"; age =
1200; }
public static void main(String []time)
{var p = new PoliceBox(); var q = new
PoliceBox();
p.color = "green"; p.age = 1400; p=q;
System.out.println("Q1="+q.color + “
Q2="+q.age+ "P1="+p.color + “ P2="+p.age);
} }
It prints Q1=blue.
It prints Q2=1200.
It prints P1=null.
It prints P2=1400.
“public void PoliceBox()” does not compile.
“p.age = 1400; “ does not compile.
“p=q;” does not compile.
None of the above.

Recommended for you

ThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and DjangoThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and Django

Class based indexes feature in Django

djangoindexesopen-source
Seamless PostgreSQL to Snowflake Data Transfer in 8 Simple Steps
Seamless PostgreSQL to Snowflake Data Transfer in 8 Simple StepsSeamless PostgreSQL to Snowflake Data Transfer in 8 Simple Steps
Seamless PostgreSQL to Snowflake Data Transfer in 8 Simple Steps

Unlock the full potential of your data by effortlessly migrating from PostgreSQL to Snowflake, the leading cloud data warehouse. This comprehensive guide presents an easy-to-follow 8-step process using Estuary Flow, an open-source data operations platform designed to simplify data pipelines. Discover how to seamlessly transfer your PostgreSQL data to Snowflake, leveraging Estuary Flow's intuitive interface and powerful real-time replication capabilities. Harness the power of both platforms to create a robust data ecosystem that drives business intelligence, analytics, and data-driven decision-making. Key Takeaways: 1. Effortless Migration: Learn how to migrate your PostgreSQL data to Snowflake in 8 simple steps, even with limited technical expertise. 2. Real-Time Insights: Achieve near-instantaneous data syncing for up-to-the-minute analytics and reporting. 3. Cost-Effective Solution: Lower your total cost of ownership (TCO) with Estuary Flow's efficient and scalable architecture. 4. Seamless Integration: Combine the strengths of PostgreSQL's transactional power with Snowflake's cloud-native scalability and data warehousing features. Don't miss out on this opportunity to unlock the full potential of your data. Read & Download this comprehensive guide now and embark on a seamless data journey from PostgreSQL to Snowflake with Estuary Flow! Try it Free: https://dashboard.estuary.dev/register

postgresqlsnowflakepostgres to snowflake
NYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdfNYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdf

Explore the craft of program and project management, hearing from Atlassian Program Managers, local thought leaders, and more.

project managementpmoatlassian community
Answer 20
Which statements about the following class are
correct? (Choose all that apply.)
public class PoliceBox {
String color; long age;
public void PoliceBox() { color = "blue"; age =
1200; }
public static void main(String []time)
{var p = new PoliceBox(); var q = new
PoliceBox();
p.color = "green"; p.age = 1400; p=q;
System.out.println("Q1="+q.color + “
Q2="+q.age+ "P1="+p.color + “ P2="+p.age);
} }
It prints Q1=blue.
It prints Q2=1200.
It prints P1=null.
It prints P2=1400.
“public void PoliceBox()” does not compile.
“p.age = 1400; “ does not compile.
“p=q;” does not compile.
None of the above.
Comment: public void PoliceBox() is a method,
not a constructor.
Question 21
What is the output of executing the
following class?
public class Salmon {
int count; { System.out.print(count+"-
"); }
{ Count++; }
public Salmon() { count = 4;
System.out.print(2+"-") ;}
public static void main(String[] args) {
System.out.print(7+"') ;
var s = new salmon();
System.out.print(s.count+“-"); } }
7-0-2-1
7-0-1-
0-7-2-1-
7-0-2-4-
0-7-1-
The class does not compile because of
“{ System.out.print(count+"-"); }”.
The class does not compile because of
“public Salmon()“.
None of the above.
Answer 21
What is the output of executing the
following class?
public class Salmon {
int count; { System.out.print(count+"-
"); }
{ Count++; }
public Salmon() { count = 4;
System.out.print(2+"-") ;}
public static void main(String[] args) {
System.out.print(7+"') ;
var s = new salmon();
System.out.print(s.count+“-"); } }
7-0-2-1
7-0-1-
0-7-2-1-
7-0-2-4-
0-7-1-
The class does not compile because of
“{ System.out.print(count+"-"); }”.
The class does not compile because of
“public Salmon()“.
None of the above.
Comment: start at main
Question 22
Given the following class, which of
the following lines of code can
independently replace INSERT
CODE HERE to make the code
compile? (Choose all that apply.)
public class Price {
public void admission() {
INSERT CODE HERE
System.out.print(amount);
} }
int Amount = 0b11;
int amount = 9L;
int amount = 0xE;
int amount = 1_2.0;
double amount = 1_0_.0;
int amount = 0b101;
double amount = 9_2.1_2;
double amount = 1_2_.0_0;

Recommended for you

Safe Work Permit Management Software for Hot Work Permits
Safe Work Permit Management Software for Hot Work PermitsSafe Work Permit Management Software for Hot Work Permits
Safe Work Permit Management Software for Hot Work Permits

Efficient hot work permit software for safe, streamlined work permit management and compliance. Enhance safety today. Contact us on +353 214536034. https://sheqnetwork.com/work-permit/

hot work permit softwarework permit softwaresafe work permit software
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTIONBITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION

Bitcoin heist prediction using ML

ENISA Threat Landscape 2023 documentation
ENISA Threat Landscape 2023 documentationENISA Threat Landscape 2023 documentation
ENISA Threat Landscape 2023 documentation

ENISA Threat Landscape 2023

Answer 22
Given the following class, which of
the following lines of code can
independently replace INSERT
CODE HERE to make the code
compile? (Choose all that apply.)
public class Price {
public void admission() {
INSERT CODE HERE
System.out.print(amount);
} }
int Amount = 0b11;
int amount = 9L;
int amount = 0xE;
int amount = 1_2.0;
double amount = 1_0_.0;
int amount = 0b101;
double amount = 9_2.1_2;
double amount = 1_2_.0_0;
Comment: _. or ._ = invalid
Question 23
Which statements about the following class
are true? (Choose all that apply.)
public class River {
int Depth = 1; float temp = 50.0;
public void flow() {
for (int i = 0; i < 1; i++) {int depth = 2;
depth++; temp--;}
System.out.println(depth);
System.out.println(temp); }
public static void main(String... s) {
new River().flow(); } }
“float temp = 50.0;” generates a compiler
error.
“int depth = 2;” generates a compiler error.
“depth++;” generates a compiler error.
“System.out.println(depth);” generates a
compiler error.
The program prints 3 at
“System.out.println(depth);”.
The program prints 4 at
“System.out.println(depth);”.
The program prints 50.0 at
“System.out.println(temp);“.
The program prints 49.0 at
“System.out.println(temp);”.
Answer 23
Which statements about the following class are
true? (Choose all that apply.)
public class River {
int Depth = 1; float temp = 50.0;
public void flow() {
for (int i = 0; i < 1; i++) {int depth = 2;
depth++; temp--;}
System.out.println(depth);
System.out.println(temp); }
public static void main(String... s) {
new River().flow(); } }
“float temp = 50.0;” generates a compiler error.
“int depth = 2;” generates a compiler error.
“depth++;” generates a compiler error.
“System.out.println(depth);” generates a
compiler error.
The program prints 3 at
“System.out.println(depth);”.
The program prints 4 at
“System.out.println(depth);”.
The program prints 50.0 at
“System.out.println(temp);“.
The program prints 49.0 at
“System.out.println(temp);”.
Comment: 50.0 needs “f” and depth is out of
scope at println
15 minute break
This is the end of chapter 1.
Chapter 2 will resume after the break.

Recommended for you

Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptxAddressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx

Enhance the top 9 user pain points with effective visual design elements to improve user experience & satisfaction. Learn the best design strategies

#ui visual designrecruitmentux
A Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdfA Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdf

A robust software testing strategy encompassing functional and non-functional testing is fundamental for development teams. These twin pillars are essential for ensuring the success of your applications. But why are they so critical? Functional testing rigorously examines the application's processes against predefined requirements, ensuring they align seamlessly. Conversely, non-functional testing evaluates performance and reliability under load, enhancing the end-user experience.

non functional testingfunctional testing
Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...
Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...
Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...

Unlock the full potential of mobile monitoring with ONEMONITAR. Our advanced and discreet app offers a comprehensive suite of features, including hidden call recording, real-time GPS tracking, message monitoring, and much more. Perfect for parents, employers, and anyone needing a reliable solution, ONEMONITAR ensures you stay informed and in control. Explore the key features of ONEMONITAR and see why it’s the trusted choice for Android device monitoring. Share this infographic to spread the word about the ultimate mobile spy app!

hidden mobile spy appmobile spy app for parentsmobile spy app for android

More Related Content

Similar to Java SE 17 Study Guide for Certification - Chapter 01

Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 Presentation
James Hamilton
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
Ganesh Samarthyam
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
Sunil OS
 
1
11
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
JWORKS powered by Ordina
 
Java performance
Java performanceJava performance
Java performance
Sergey D
 
Core java
Core javaCore java
Core java
prabhatjon
 
Java practical
Java practicalJava practical
Java practical
william otto
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
fntsofttech
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
CodeOps Technologies LLP
 
Java tut1
Java tut1Java tut1
Java tut1
Ajmal Khan
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Vijay A Raj
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
guest5c8bd1
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
Abdul Aziz
 
Finding bugs that matter with Findbugs
Finding bugs that matter with FindbugsFinding bugs that matter with Findbugs
Finding bugs that matter with Findbugs
Carol McDonald
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
Rasan Samarasinghe
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
walia Shaan
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 Quizzes
Steven Luo
 
Core java day1
Core java day1Core java day1
Core java day1
Soham Sengupta
 
Java puzzles
Java puzzlesJava puzzles
Java puzzles
Nikola Petrov
 

Similar to Java SE 17 Study Guide for Certification - Chapter 01 (20)

Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 Presentation
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
 
1
11
1
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Java performance
Java performanceJava performance
Java performance
 
Core java
Core javaCore java
Core java
 
Java practical
Java practicalJava practical
Java practical
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
 
Finding bugs that matter with Findbugs
Finding bugs that matter with FindbugsFinding bugs that matter with Findbugs
Finding bugs that matter with Findbugs
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 Quizzes
 
Core java day1
Core java day1Core java day1
Core java day1
 
Java puzzles
Java puzzlesJava puzzles
Java puzzles
 

Recently uploaded

Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...
Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...
Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.
bhatinidhi2001
 
introduction of Ansys software and basic and advance knowledge of modelling s...
introduction of Ansys software and basic and advance knowledge of modelling s...introduction of Ansys software and basic and advance knowledge of modelling s...
introduction of Ansys software and basic and advance knowledge of modelling s...
sachin chaurasia
 
React Native vs Flutter - SSTech System
React Native vs Flutter  - SSTech SystemReact Native vs Flutter  - SSTech System
React Native vs Flutter - SSTech System
SSTech System
 
Development of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML TechnologiesDevelopment of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML Technologies
MaisnamLuwangPibarel
 
Leading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptxLeading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptx
taskroupseo
 
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
karim wahed
 
ANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdfANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdf
sachin chaurasia
 
MVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptxMVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptx
Mitchell Marsh
 
WEBINAR SLIDES: CCX for Cloud Service Providers
WEBINAR SLIDES: CCX for Cloud Service ProvidersWEBINAR SLIDES: CCX for Cloud Service Providers
WEBINAR SLIDES: CCX for Cloud Service Providers
Severalnines
 
ThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and DjangoThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and Django
akshesh doshi
 
Seamless PostgreSQL to Snowflake Data Transfer in 8 Simple Steps
Seamless PostgreSQL to Snowflake Data Transfer in 8 Simple StepsSeamless PostgreSQL to Snowflake Data Transfer in 8 Simple Steps
Seamless PostgreSQL to Snowflake Data Transfer in 8 Simple Steps
Estuary Flow
 
NYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdfNYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdf
AUGNYC
 
Safe Work Permit Management Software for Hot Work Permits
Safe Work Permit Management Software for Hot Work PermitsSafe Work Permit Management Software for Hot Work Permits
Safe Work Permit Management Software for Hot Work Permits
sheqnetworkmarketing
 
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTIONBITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
ssuser2b426d1
 
ENISA Threat Landscape 2023 documentation
ENISA Threat Landscape 2023 documentationENISA Threat Landscape 2023 documentation
ENISA Threat Landscape 2023 documentation
sofiafernandezon
 
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptxAddressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Sparity1
 
A Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdfA Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdf
kalichargn70th171
 
Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...
Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...
Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...
onemonitarsoftware
 
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdfResponsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Trackobit
 

Recently uploaded (20)

Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...
Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...
Abortion pills in Fujairah *((+971588192166*)☎️)¥) **Effective Abortion Pills...
 
CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.
 
introduction of Ansys software and basic and advance knowledge of modelling s...
introduction of Ansys software and basic and advance knowledge of modelling s...introduction of Ansys software and basic and advance knowledge of modelling s...
introduction of Ansys software and basic and advance knowledge of modelling s...
 
React Native vs Flutter - SSTech System
React Native vs Flutter  - SSTech SystemReact Native vs Flutter  - SSTech System
React Native vs Flutter - SSTech System
 
Development of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML TechnologiesDevelopment of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML Technologies
 
Leading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptxLeading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptx
 
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
 
ANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdfANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdf
 
MVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptxMVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptx
 
WEBINAR SLIDES: CCX for Cloud Service Providers
WEBINAR SLIDES: CCX for Cloud Service ProvidersWEBINAR SLIDES: CCX for Cloud Service Providers
WEBINAR SLIDES: CCX for Cloud Service Providers
 
ThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and DjangoThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and Django
 
Seamless PostgreSQL to Snowflake Data Transfer in 8 Simple Steps
Seamless PostgreSQL to Snowflake Data Transfer in 8 Simple StepsSeamless PostgreSQL to Snowflake Data Transfer in 8 Simple Steps
Seamless PostgreSQL to Snowflake Data Transfer in 8 Simple Steps
 
NYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdfNYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdf
 
Safe Work Permit Management Software for Hot Work Permits
Safe Work Permit Management Software for Hot Work PermitsSafe Work Permit Management Software for Hot Work Permits
Safe Work Permit Management Software for Hot Work Permits
 
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTIONBITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
 
ENISA Threat Landscape 2023 documentation
ENISA Threat Landscape 2023 documentationENISA Threat Landscape 2023 documentation
ENISA Threat Landscape 2023 documentation
 
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptxAddressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
 
A Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdfA Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdf
 
Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...
Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...
Discover the Power of ONEMONITAR: The Ultimate Mobile Spy App for Android Dev...
 
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdfResponsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
 

Java SE 17 Study Guide for Certification - Chapter 01

  • 1. Java SE 17 Study Guide Chapter 1 Bill Herman WilliamRobertHerman@Gmail.com
  • 2. Question 1 Which of the following are legal entry point methods that can be run from the command line? (Choose all that apply) private static void main(String[] args) public static final main(String[] args) public void main(String[] args) public static final void main(String[] args) public static void main(String[] args) public static main(String[] args)
  • 3. Answer 1 Which of the following are legal entry point methods that can be run from the command line? (Choose all that apply) private static void main(String[] args) public static final main(String[] args) public void main(String[] args) public static final void main(String[] args) public static void main(String[] args) public static main(String[] args) Comment: Final is optional
  • 4. Question 2 What order of statements will compile successfully? class Rabbit {} import java.util.*; package animals; import java.util.*; package animals; class Rabbit {} package animals; import java.util.*; class Rabbit {} import java.util.*; class Rabbit {} package animals; class Rabbit {} class Rabbit {} package animals; None of the above
  • 5. Answer 2 What order of statements will compile successfully? class Rabbit {} import java.util.*; package animals; import java.util.*; package animals; class Rabbit {} package animals; import java.util.*; class Rabbit {} import java.util.*; class Rabbit {} package animals; class Rabbit {} class Rabbit {} package animals; None of the above Comment: package & import optional: package then import then class
  • 6. Question 3 Which of the following are true? (Choose all that apply.) public class Bunny { public static void main(String[] x) { Bunny bun = new Bunny(); } } Bunny is a class. bun is a class. main is a class. Bunny is a reference to an object. bun is a reference to an object. main is a reference to an object. The main () method doesn't run because the parameter name is incorrect.
  • 7. Question 3 Which of the following are true? (Choose all that apply.) public class Bunny { public static void main(String[] x) { Bunny bun = new Bunny(); } } Bunny is a class. bun is a class. main is a class. Bunny is a reference to an object. bun is a reference to an object. main is a reference to an object. The main () method doesn't run because the parameter name is incorrect.
  • 8. Question 4 Which of the following are valid Java identifiers? (Choose all that apply.) _ _helloWorld$ true java.lang Public 1980_s _Q2_
  • 9. Answer 4 Which of the following are valid Java identifiers? (Choose all that apply.) _ (single underscore not allowed) _helloWorld$ true (reserved word) java.lang (contains .) Public 1980_s (starts with number) _Q2_
  • 10. Question 5 Which statements about the following program are correct? (Choose all that apply.) 2: public class Bear { 3: private Bear pandaBear; 4: private void roar(Bear b) { 5: System.out.println("Roar!"); 6: pandaBear = b; 7: } 8: public static void main(String[] args) { 9: Bear brownBear = new Bear(); 10: Bear polarBear = new Bear(); 11: brownBear.roar(polarBear); 12: polarBear = null; 13: brownBear = null; 14: System.gc(); } } The object created on line 9 is eligible for garbage collection after line 13. The object created on line 9 is eligible for garbage collection after line 14. The object created on line 10 is eligible for garbage collection after line 12. The object created on line 10 is eligible for garbage collection after line 13. Garbage collection is guaranteed to run. Garbage collection might or might not run. The code does not compile.
  • 11. Answer 5 Which statements about the following program are correct? (Choose all that apply.) 2: public class Bear { 3: private Bear pandaBear; 4: private void roar(Bear b) { 5: System.out.println("Roar!"); 6: pandaBear = b; 7: } 8: public static void main(String[] args) { 9: Bear brownBear = new Bear(); 10: Bear polarBear = new Bear(); 11: brownBear.roar(polarBear); 12: polarBear = null; 13: brownBear = null; 14: System.gc(); } } The object created on line 9 is eligible for garbage collection after line 13. (set to null) The object created on line 9 is eligible for garbage collection after line 14. (new Bear()) The object created on line 10 is eligible for garbage collection after line 12. (new Bear()) The object created on line 10 is eligible for garbage collection after line 13. (set to null) Garbage collection is guaranteed to run. Garbage collection might or might not run. The code does not compile.
  • 12. Question 6 Assuming the following class compiles, how many variables defined in the class or method are in scope on the line marked on line 14? 1: public class Camel { 2: { int hairs = 3_000_0; } 3: long water, air=2; 4: boolean twoHumps = true; 5: public void spit(float distance) { 6: var path = ""; 7: { double teeth = 32 + distance++; } 8: while(water > 0) { int age = twoHumps ? i : 2; Short i=-i; for(i=0; i<10; i++) {var Private = 2; { // SCOPE } } } 2 3 4 5 6 7 None of the above
  • 13. Question 6 Assuming the following class compiles, how many variables defined in the class or method are in scope on the line marked at // SCOPE? 1: public class Camel { 2: { int hairs = 3_000_0; } 3: long water, air=2; 4: boolean twoHumps = true; 5: public void spit(float distance) { 6: var path = ""; 7: { double teeth = 32 + distance++; } 8: while(water > 0) { int age = twoHumps ? i : 2; Short i=-i; for(i=0; i<10; i++) {var Private = 2; { // SCOPE } } } 2 3 4 5 6 7 None of the above
  • 14. Question 7 Which are true about this code? (Choose all that apply.) public class KitchenSink { private int numForks; public static void main(String[] args) { int numKnives; System.out.print(""" "# forks = " + numForks + " # knives = " + numKnives + # cups = 0"""); } } The output includes: # forks = 0. The output includes: # knives = 0. The output includes: # cups = 0. The output includes a blank line. The output includes one or more lines that begin with whitespace. The code does not compile.
  • 15. Answer 7 Which are true about this code? (Choose all that apply.) public class KitchenSink { private int numForks; public static void main(String[] args) { int numKnives; System.out.print(""" "# forks = " + numForks + " # knives = " + numKnives + # cups = 0"""); } } The output includes: # forks = 0. The output includes: # knives = 0. The output includes: # cups = 0. The output includes a blank line. The output includes one or more lines that begin with whitespace. The code does not compile. Comment: forks and knives are never used
  • 16. Question 8 Which of the following code snippets about var compile without issue when used in a method? (Choose all that apply.) var spring = null; var fall = "leaves"; var evening = 2; evening = null; var night = Integer.valueof(3); var day = 1/0; var winter = 12, cold; var fall = 2, autumn = 2; var morning = ""; morning = null;
  • 17. Answer 8 Which of the following code snippets about var compile without issue when used in a method? (Choose all that apply.) var spring = null; var fall = "leaves"; var evening = 2; evening = null; var night = Integer.valueof(3); var day = 1/0; var winter = 12, cold; var fall = 2, autumn = 2; var morning = ""; morning = null; Comment: var not allowed multi
  • 18. Question 9 Which of the following are correct? (Choose all that apply.) An instance variable of type float defaults to 0. An instance variable of type char defaults to null. A local variable of type double defaults to 0.0. A local variable of type int defaults to null. A class variable of type String defaults to null. A class variable of type String defaults to the empty string "". None of the above.
  • 19. Answer 9 Which of the following are correct? (Choose all that apply.) An instance variable of type float defaults to 0. An instance variable of type char defaults to null. A local variable of type double defaults to 0.0. A local variable of type int defaults to null. A class variable of type String defaults to null. A class variable of type String defaults to the empty string "". None of the above.
  • 20. Question 10 Which of the following expressions, when inserted independently into the blank line, allow the code to compile? (Choose all that apply.) public void printMagicData() { var magic = ___________________; System.out.println (magic) ; } 3_1 1_329_.0 3_13.0_ 5_291._2 2_234.0_0 9___6 _1_3_5_0
  • 21. Answer 10 Which of the following expressions, when inserted independently into the blank line, allow the code to compile? (Choose all that apply.) public void printMagicData() { var magic = ___________________; System.out.println (magic) ; } 3_1 1_329_.0 3_13.0_ 5_291._2 2_234.0_0 9___6 _1_3_5_0 Comment: _ is legal if not at the beginning or end or next to “.”
  • 22. Question 11 Given the following two class files, what is the maximum number of imports that can be removed and have the code still compile? // Water.java package aquarium; public class Water { } // Tank.java package aquarium; import java.lang.*; import java.lang.System; import aquarium.Water; import aquarium.*; public class Tank { public void print(Water water) { System.out.println(water); } } 0 1 2 3 4 Does not compile
  • 23. Answer 11 Given the following two class files, what is the maximum number of imports that can be removed and have the code still compile? // Water.java package aquarium; public class Water { } // Tank.java package aquarium; import java.lang.*; import java.lang.System; import aquarium.Water; import aquarium.*; public class Tank { public void print(Water water) { System.out.println(water); } } 0 1 2 3 4 Does not compile Comment: java.lang included as default. Aquarium already imported.
  • 24. Question 12 Which statements about the following class are correct? (Choose all that apply.) 1: public class ClownFish { 2: int gills = 0, double weight=2; 3: { int fins = gills; } 4: void print(int length = 3) { 5: System.out.println(gills); 6: System.out.println(weight); 7: System.out.println(fins); 8: System.out.println(length); 9:} } Line 2 generates a compiler error. Line 3 generates a compiler error. Line 4 generates a compiler error. Line 7 generates a compiler error. The code prints 0. The code prints 2.0. The code prints 2. The code prints 3.
  • 25. Answer 12 Which statements about the following class are correct? (Choose all that apply.) 1: public class ClownFish { 2: int gills = 0, double weight=2; 3: { int fins = gills; } 4: void print(int length = 3) { 5: System.out.println(gills); 6: System.out.println(weight); 7: System.out.println(fins); 8: System.out.println(length); 9:} } Line 2 generates a compiler error. Line 3 generates a compiler error. Line 4 generates a compiler error. Line 7 generates a compiler error. The code prints 0. The code prints 2.0. The code prints 2. The code prints 3. Comment: Line 2 is invalid because different types and comma instead of semi- colon. Line 4 is not a valid parameter signature.
  • 26. Question 13 Given the following classes, which of the following snippets can independently be inserted in place of INSERT IMPORTS HERE and have the code compile? (Choose all that apply.) package aquarium; public class Water { boolean salty = false; } package aquarium.jellies; public class Water { boolean salty = true;} package employee; INSERT IMPORTS HERE public class WaterFiller { Water water; } import aquarium.*; import aquarium.Water; import aquarium.jellies.*; import aquarium.*; import aquarium.jellies.Water; import aquarium.*; import aquarium.jellies.*; import aquarium.Water; import aquarium.jellies.Water; None of these imports can make the code compile.
  • 27. Answer 13 Given the following classes, which of the following snippets can independently be inserted in place of INSERT IMPORTS HERE and have the code compile? (Choose all that apply.) package aquarium; public class Water { boolean salty = false; } package aquarium.jellies; public class Water { boolean salty = true;} package employee; INSERT IMPORTS HERE public class WaterFiller { Water water; } import aquarium.*; import aquarium.Water; import aquarium.jellies.*; import aquarium.*; import aquarium.jellies.Water; import aquarium.*; import aquarium.jellies.*; import aquarium.Water; import aquarium.jellies.Water; None of these imports can make the code compile. Comment: Duplicate class name (Water) not selected correctly.
  • 28. Question 14 Which of the following statements about the code snippet are true?(Choose all that apply.) 3: short numPets = 5L; 4: int numGrains = 2.0; 5: String name = "Scruffy"; 6: int d = numPets.length(); 7: int e = numGrains.length; 8: int f = name.length(); Line 3 generates a compiler error. Line 4 generates a compiler error. Line 5 generates a compiler error. Line 6 generates a compiler error. Line 7 generates a compiler error. Line 8 generates a compiler error.
  • 29. Answer 14 Which of the following statements about the code snippet are true?(Choose all that apply.) 3: short numPets = 5L; 4: int numGrains = 2.0; 5: String name = "Scruffy"; 6: int d = numPets.length(); 7: int e = numGrains.length; 8: int f = name.length(); Line 3 generates a compiler error. Line 4 generates a compiler error. Line 5 generates a compiler error. Line 6 generates a compiler error. Line 7 generates a compiler error. Line 8 generates a compiler error.
  • 30. Question 15 Which of the following statements about garbage collection are correct? (Choose all that apply.) Calling System.gc( ) is guaranteed to free up memory by destroying objects eligible for garbage collection. Garbage collection runs on a set schedule. Garbage collection allows the JVM to reclaim memory for other objects. Garbage collection runs when your program has used up half the available memory. An object may be eligible for garbage collection but never removed from the heap. An object is eligible for garbage collection once no references to it are accessible in the program. Marking a variable final means its associated object will never be garbage collected.
  • 31. Answer 15 Which of the following statements about garbage collection are correct? (Choose all that apply.) Calling System.gc( ) is guaranteed to free up memory by destroying objects eligible for garbage collection. Garbage collection runs on a set schedule. Garbage collection allows the JVM to reclaim memory for other objects. Garbage collection runs when your program has used up half the available memory. An object may be eligible for garbage collection but never removed from the heap. An object is eligible for garbage collection once no references to it are accessible in the program. Marking a variable final means its associated object will never be garbage collected.
  • 32. Question 16 Which are true about this code? (Choose all that apply.) var blocky = """ squirrel s pigeon termite"""; System.out.print(blocky); It outputs two lines. It outputs three lines. It outputs four lines. There is one line with trailing whitespace. There are two lines with trailing whitespace. If we indented each line five characters, it would change the output.
  • 33. Answer 16 Which are true about this code? (Choose all that apply.) var blocky = """ squirrel s pigeon termite"""; System.out.print(blocky); It outputs two lines. It outputs three lines. It outputs four lines. There is one line with trailing whitespace. There are two lines with trailing whitespace. If we indented each line five characters, it would change the output. Comment: s = keep white space, means remove line break
  • 34. Question 17 What lines are printed by the following program? (Choose all that apply.) 1: public class WaterBottle { 2: private String brand; 3: private boolean empty; 4: public static float code; 5: public static void main(String[] args) { 6: WaterBottle wb = new WaterBottle(); 7: System.out.println("Empty = " + wb.empty); 8: System.out.println("Brand = " + wb.brand); 9: System.out.println("Code = " + code); 10: } } Line 8 generates a compiler error. Line 9 generates a compiler error. Empty = Empty = false Brand = Brand = null Code = 0.0 Code = 0f
  • 35. Answer 17 What lines are printed by the following program? (Choose all that apply.) 1: public class WaterBottle { 2: private String brand; 3: private boolean empty; 4: public static float code; 5: public static void main(String[] args) { 6: WaterBottle wb = new WaterBottle(); 7: System.out.println("Empty = " + wb.empty); 8: System.out.println("Brand = " + wb.brand); 9: System.out.println("Code = " + code); 10: } } Line 8 generates a compiler error. Line 9 generates a compiler error. Empty = Empty = false Brand = Brand = null Code = 0.0 Code = 0f Comment: printed values are defaults
  • 36. Question 18 Which of the following statements about var are true? (Choose all that apply.) A var can be used as a constructor parameter. The type of a var is known at compile time. A var cannot be used as an instance variable. A var can be used in a multiple variable assignment statement. The value of a var cannot change at runtime. The type of a var cannot change at runtime. The word var is a reserved word in Java.
  • 37. Answer 18 Which of the following statements about var are true? (Choose all that apply.) A var can be used as a constructor parameter. The type of a var is known at compile time. A var cannot be used as an instance variable. A var can be used in a multiple variable assignment statement. The value of a var cannot change at runtime. The type of a var cannot change at runtime. The word var is a reserved word in Java.
  • 38. Question 19 Which are true about the following code? (Choose all that apply.) var num1 = Long.parseLong(“100"); var num2 = Long.valueof("100"); System.out.println(Long.max(num 1, num2)) ; The output is 100. The output is 200. The code does not compile. num1 is a primitive. num2 is a primitive.
  • 39. Answer 19 Which are true about the following code? (Choose all that apply.) var num1 = Long.parseLong(“100"); var num2 = Long.valueof("100"); System.out.println(Long.max(num 1, num2)) ; The output is 100. The output is 200. The code does not compile. num1 is a primitive. num2 is a primitive.
  • 40. Question 20 Which statements about the following class are correct? (Choose all that apply.) public class PoliceBox { String color; long age; public void PoliceBox() { color = "blue"; age = 1200; } public static void main(String []time) {var p = new PoliceBox(); var q = new PoliceBox(); p.color = "green"; p.age = 1400; p=q; System.out.println("Q1="+q.color + “ Q2="+q.age+ "P1="+p.color + “ P2="+p.age); } } It prints Q1=blue. It prints Q2=1200. It prints P1=null. It prints P2=1400. “public void PoliceBox()” does not compile. “p.age = 1400; “ does not compile. “p=q;” does not compile. None of the above.
  • 41. Answer 20 Which statements about the following class are correct? (Choose all that apply.) public class PoliceBox { String color; long age; public void PoliceBox() { color = "blue"; age = 1200; } public static void main(String []time) {var p = new PoliceBox(); var q = new PoliceBox(); p.color = "green"; p.age = 1400; p=q; System.out.println("Q1="+q.color + “ Q2="+q.age+ "P1="+p.color + “ P2="+p.age); } } It prints Q1=blue. It prints Q2=1200. It prints P1=null. It prints P2=1400. “public void PoliceBox()” does not compile. “p.age = 1400; “ does not compile. “p=q;” does not compile. None of the above. Comment: public void PoliceBox() is a method, not a constructor.
  • 42. Question 21 What is the output of executing the following class? public class Salmon { int count; { System.out.print(count+"- "); } { Count++; } public Salmon() { count = 4; System.out.print(2+"-") ;} public static void main(String[] args) { System.out.print(7+"') ; var s = new salmon(); System.out.print(s.count+“-"); } } 7-0-2-1 7-0-1- 0-7-2-1- 7-0-2-4- 0-7-1- The class does not compile because of “{ System.out.print(count+"-"); }”. The class does not compile because of “public Salmon()“. None of the above.
  • 43. Answer 21 What is the output of executing the following class? public class Salmon { int count; { System.out.print(count+"- "); } { Count++; } public Salmon() { count = 4; System.out.print(2+"-") ;} public static void main(String[] args) { System.out.print(7+"') ; var s = new salmon(); System.out.print(s.count+“-"); } } 7-0-2-1 7-0-1- 0-7-2-1- 7-0-2-4- 0-7-1- The class does not compile because of “{ System.out.print(count+"-"); }”. The class does not compile because of “public Salmon()“. None of the above. Comment: start at main
  • 44. Question 22 Given the following class, which of the following lines of code can independently replace INSERT CODE HERE to make the code compile? (Choose all that apply.) public class Price { public void admission() { INSERT CODE HERE System.out.print(amount); } } int Amount = 0b11; int amount = 9L; int amount = 0xE; int amount = 1_2.0; double amount = 1_0_.0; int amount = 0b101; double amount = 9_2.1_2; double amount = 1_2_.0_0;
  • 45. Answer 22 Given the following class, which of the following lines of code can independently replace INSERT CODE HERE to make the code compile? (Choose all that apply.) public class Price { public void admission() { INSERT CODE HERE System.out.print(amount); } } int Amount = 0b11; int amount = 9L; int amount = 0xE; int amount = 1_2.0; double amount = 1_0_.0; int amount = 0b101; double amount = 9_2.1_2; double amount = 1_2_.0_0; Comment: _. or ._ = invalid
  • 46. Question 23 Which statements about the following class are true? (Choose all that apply.) public class River { int Depth = 1; float temp = 50.0; public void flow() { for (int i = 0; i < 1; i++) {int depth = 2; depth++; temp--;} System.out.println(depth); System.out.println(temp); } public static void main(String... s) { new River().flow(); } } “float temp = 50.0;” generates a compiler error. “int depth = 2;” generates a compiler error. “depth++;” generates a compiler error. “System.out.println(depth);” generates a compiler error. The program prints 3 at “System.out.println(depth);”. The program prints 4 at “System.out.println(depth);”. The program prints 50.0 at “System.out.println(temp);“. The program prints 49.0 at “System.out.println(temp);”.
  • 47. Answer 23 Which statements about the following class are true? (Choose all that apply.) public class River { int Depth = 1; float temp = 50.0; public void flow() { for (int i = 0; i < 1; i++) {int depth = 2; depth++; temp--;} System.out.println(depth); System.out.println(temp); } public static void main(String... s) { new River().flow(); } } “float temp = 50.0;” generates a compiler error. “int depth = 2;” generates a compiler error. “depth++;” generates a compiler error. “System.out.println(depth);” generates a compiler error. The program prints 3 at “System.out.println(depth);”. The program prints 4 at “System.out.println(depth);”. The program prints 50.0 at “System.out.println(temp);“. The program prints 49.0 at “System.out.println(temp);”. Comment: 50.0 needs “f” and depth is out of scope at println
  • 48. 15 minute break This is the end of chapter 1. Chapter 2 will resume after the break.