Unit 3 Check for Understanding 3.5-3.7

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the below is a logical operator? ! ## ** %

!

Which of the following logical statements is equivalent to !(A || B) Where A and B are boolean values !A && !B !A || !B !A || B A && B

!A && !B

Which of the following logical statements is equivalent to !(A && B) Where A and B are boolean values !A && B !A && !B !A || !B !A || B

!A || !B

What value of x would make this boolean expression evaluate to false? (x < 10) && (x != 5) Any value less than 10 Any value less than 10 except for 5 The only time it is false is when x = 5. Any value greater than or equal to 10

Any value greater than or equal to 10

Given the following Circle class public class Circle { private int radius; public Circle(int theRadius) { radius = theRadius; } public void setRadius(int newRadius) { radius = newRadius; } public int getRadius() { return radius; } public boolean equals(Circle other) { return radius == other.getRadius(); } } What is the output of the following code snippet? Circle one = new Circle(10); Circle two = new Circle(10); System.out.println(one == two); true false

False

What boolean value is held in the following boolean variable if hasHeadlight is true and hasBikelight is false? boolean cannotNightBike = !(hasHeadlight || hasBikelight); True False

False

In the following line of code: boolean shortCircuit = true || (5 / 0 == 0); Will the 5 / 0 == 0 operation be evaluated? Yes No

No

What is the proper way to compare String values in Java? The == operator The .equals() String method The = operator The | operator

The .equals() String method

What boolean value is held in the following boolean variable if hasBike is true and hasHelmet is false? boolean cannotBike = !(hasBike && hasHelmet); True False

True

In the following line of code: boolean shortCircuit = true && (5 / 0 == 0); Will the 5 / 0 == 0 operation be evaluated? Yes No

Yes

Which of the following Boolean expressions will yield true after the code snippet executes? String str1 = new String("Karel"); String str2 = "CodeHS"; String str3 = "Karel"; str2 = str1; str1 == str2 && str1 == str3 str1 != str2 && str1.equals(str3) str1 == str2 && str1.equals(str3) None of the above will evaluate to true after this code snippet executes.

str1 == str2 && str1.equals(str3)

Given the following Circle class public class Circle { private int radius; public Circle(int theRadius) { radius = theRadius; } public void setRadius(int newRadius) { radius = newRadius; } public int getRadius() { return radius; } public boolean equals(Circle other) { return radius == other.getRadius(); } } What is the output of the following code snippet? public void run() { Circle one = new Circle(5); Circle two = new Circle(10); foo(two); System.out.println(one.equals(two)); } public void foo(Circle x) { x.setRadius(5); } true false

true

Logical equality compares the data of the objects. False True

true

Reference equality uses the equality operator (==) and compares the references (addresses in memory) of two objects. True False

true

What does this Java expression evaluate to? true && !false true false

true


Ensembles d'études connexes

Psychology 041 Chapter 14: Socioemotional Development in Middle Adulthood

View Set

STATE ACCOUNT QUIZIZIZIZIZZIZIIZIZIZI

View Set

Chapter 5: Understanding Children from Birth to Age Two

View Set

Chapter 1 - Enterprise Systems for Management - Motiwalla 2nd

View Set

Business Law Chapter 11 Nature and Terminology

View Set

Homework 3: Light and Telescopes

View Set

Wk 1 - Practice: Ch. 1, What Do We Mean by Leadership?

View Set