
#201 Unit 2 Lesson 12 Notes
Presentation
•
Computers
•
11th Grade
•
Practice Problem
•
Easy
Myra Deister
Used 3+ times
FREE Resource
34 Slides • 8 Questions
1
Computer Science A
Unit 2 - Lesson 12
Printing Objects
2
Warm Up
3
CSA
Printing Objects - Warm Up
A software engineer is developing a travel
app. The user must be able to choose a
hotel and a flight for their trip.
▶What classes should the software
engineer develop? What attributes and
behaviors might each class have?
💡
Discuss:
📝
Unit 2 Guide
4
Open Ended
A software engineer is developing a travel app. The user must be able to choose a hotel and a flight for their trip.
What classes should the software engineer develop?
What attributes and behaviors might each class have?
5
Activity
6
CSA
🎯
Lesson Objectives
By the end of this lesson, you will be able to . . .
●
Write a toString() method to display information about the
state of an object to the console
●
Use escape sequences to format output
Printing Objects - Activity
7
CSA
🚀
Question of the Day
How can I easily display information
about an object?
Printing Objects - Activity
8
CSA
✅
Do This:
Predict
and Run
Predict
1. Predict the output of
the program
There are no wrong
answers!
Printing Objects - Activity
9
Open Ended
What is the output? Link to code: https://docs.google.com/document/d/e/2PACX-1vTcZmPx1IqXQA2KxZ5RSID-1BFwpolNmP26ZiNtd-6sIr2PaSqW_0Dwq2lgMeCDYan-HH6CDO6X_NWZ/pub
10
CSA
Printing Objects - Activity
When printing an object, the toString() method
of the Object class is called.
PizzaRunner.java
1 public class PizzaRunner {
2 public static void main(String[] args) {
3 Pizza cheesePizza = new Pizza("cheese");
4 System.out.print(cheesePizza);
5 }
6 }
Console
Pizza@3c717ef2
11
CSA
Printing Objects - Activity
The toString() method in the Object class returns a String
that consists of the name of the class, the @ symbol, and the
hash code of the object.
A hash code is the
value associated with
each object in Java.
PizzaRunner.java
1 public class PizzaRunner {
2 public static void main(String[] args) {
3 Pizza cheesePizza = new Pizza("cheese");
4 System.out.print(cheesePizza);
5 }
6 }
Console
Pizza@3c717ef2
12
Discuss:
HOLDthat
THOUGHT
CSA
Why do you think the toString()
method in the Object class doesn't
print the values stored in the
instance variables?
Printing Objects - Activity
📝
Unit 2 Guide
13
Open Ended
Why do you think the toString() method in the Object class doesn't print the values stored in the instance variables?
14
💡
Discuss:
HOLDthat
THOUGHT
CSA
What did you notice about the way
the toString() method is called?
Printing Objects - Activity
📝
Unit 2 Guide
15
Open Ended
What did you notice about the way the toString() method is called?
16
CSA
Printing Objects - Activity
The toString() method is automatically called when an object
reference is passed to a print statement or when an object reference
is concatenated with a String.
PizzaRunner.java
1 public class PizzaRunner {
2 public static void main(String[] args) {
3 Pizza cheesePizza = new Pizza("cheese");
4 System.out.print(cheesePizza);
5 }
6 }
Console
Pizza@3c717ef2
17
CSA
Printing Objects - Activity
To override is to define a method in a subclass with the
same method signature as a method inherited from a
superclass.
Since the Object class is the
superclass of all classes, we can
override the toString() method
in our classes to provide more
useful information about the
state of our objects.
📝
Unit 2 Guide
18
CSA
Printing Objects - Activity
Overriding the toString() Method
public String toString() {
return topping + " pizza";
}
The method signature is the same as the toString() method in the
Object class. It has the same return type, name, and no parameters.
📝
Unit 2 Guide
19
CSA
Printing Objects - Activity
Overriding the toString() Method
public String toString() {
return topping + " pizza";
}
In the body of the toString() method, we return a String that
contains information about the object.
📝
Unit 2 Guide
20
💡
Discuss:
Retrieve
your knowledge
and ideas and write
it down silently
Pair
up with a neighbor
and talk about your
reflections
Share
your thoughts in a
class discussion
CSA
How could we include the
information in the superclass
toString() method in a
subclass toString() method?
Printing Objects - Activity
📝
Unit 2 Guide
21
Open Ended
How could we include the information in the superclass toString() method in a subclass toString() method?
22
CSA
Printing Objects - Activity
We can use the super keyword to call the superclass
version of a method in a subclass.
public String toString() {
return super.toString() + " with " + stuffing + " stuffed crust";
}
public String toString() {
return topping + " pizza";
}
StuffedPizza.java
Pizza.java
23
CSA
Printing Objects - Activity
We can use escape sequences to format the output.
An escape sequence starts with a \ to indicate how
to display a String.
Escape Sequence
Description
\n new line
\" double quote
\\ backslash
📝
Unit 2 Guide
24
CSA
Printing Objects - Activity
We use the escape
sequence \" when we want
to print a quotation ( " ).
System.out.print("\"Best cookie shop!\" - Anonymous");
What is output by
this line of code?
25
Open Ended
What is output by this code?
System.out.print("\"Best cookie shop!\" - Anonymous");
26
27
CSA
Printing Objects - Activity
We use the escape
sequence \n when we want
to print a new line.
System.out.println("C\nA\nK\nE");
What is output by
this line of code?
28
Open Ended
What is output by this code?
System.out.println("C\nA\nK\nE");
29
CSA
Printing Objects - Activity
We use the escape
sequence \n when we want
to print a new line.
System.out.println("C\nA\nK\nE");
What is output by
this line of code?
> C
A
K
E
> _
30
CSA
Printing Objects - Activity
We use the escape
sequence \\ when we want
to print a backslash.
System.out.println("Laugh \\S'more\\ worry less.");
What is output by
this line of code?
31
Open Ended
What is output by this code?
System.out.println("Laugh \\S'more\\ worry less.");
32
CSA
Printing Objects - Activity
We use the escape
sequence \\ when we want
to print a backslash.
System.out.println("Laugh \\S'more\\ worry less.");
What is output by
this line of code?
Laugh \S'more\ worry less.
> _
33
Wrap Up
34
🎉
Today, you learned about . . .
CSA
● Writing a toString() method to display information
about the state of an object to the console
● Using escape sequences to format output
Printing Objects - Wrap Up
35
🚀
Question of the Day
CSA
How can I easily display information
about an object?
Printing Objects - Wrap Up
36
CSA
● override: to define a method in a subclass with
the same method signature as a method
inherited from a superclass
● escape sequence: starts with a \ to indicate how
to display a String
💼
Key Vocabulary
Printing Objects - Wrap Up
37
CSA
✅
Do This:
Investigate
and Modify
📝
Navigate to Lesson 12, Level 1
1. Predict and Run on Level 1
2. Investigate the code on Levels
2 and 3
3. Make changes as prompted
and observe the results
Printing Objects - Activity
38
CSA
✅
Do This:
🎉
Practice
Navigate to Lesson 12, Level 4
1. Level 4 - Check for Understanding
2. Level 5 - Complete a choice level to
write a toString() method
3. Level 6 - Write a toString() method
in the Dessert class
4. Level 7 - Write a toString() method
in the Dessert subclass
A
B
C
D
Printing Objects - Activity
39
CSA
Printing Objects - Wrap Up
Show What You Know Week
Store
Management
Project
Burger Class
FRQ
Multiple-Choice
Assessment
40
CSA
Printing Objects - Wrap Up
Store Management Project
Use your knowledge of object-oriented
programming and class structure and design to
create your store management system:
●Create a class hierarchy
●Declare instance variables
●Write constructors
●Implement accessor and mutator methods
●Implement a toString() method
41
CSA
Printing Objects - Activity
Commit Your Code!
Commit your code and add a
comment about what the
work you completed.
Commit Code
Backpack
Save your Dessert classes
to the Backpack.
42
CSA
Unit 2 Study Guide
The Unit 2 Study Guide covers
objectives, programming concepts,
and syntax to help you prepare to . . .
Show What You Know!
Printing Objects - Wrap Up
Computer Science A
Unit 2 - Lesson 12
Printing Objects
Show answer
Auto Play
Slide 1 / 42
SLIDE
Similar Resources on Wayground
36 questions
Instalasi Sistem Operasi Windows 11
Presentation
•
10th Grade
35 questions
Q2 Benchmark - Critical Thinking
Presentation
•
11th Grade
38 questions
AP Rotational Motion Review
Presentation
•
11th Grade
40 questions
Circle Vocabulary Part 1
Presentation
•
10th Grade
37 questions
English 26/04
Presentation
•
KG
38 questions
Intro to Federalist 10
Presentation
•
11th Grade
36 questions
3.1 Pemecahan Masalah dalam Pemrograman
Presentation
•
11th Grade
37 questions
N5 SDD Revision
Presentation
•
11th Grade
Popular Resources on Wayground
16 questions
Grade 3 Simulation Assessment 2
Quiz
•
3rd Grade
19 questions
HCS Grade 5 Simulation Assessment_1 2526sy
Quiz
•
5th Grade
10 questions
Cinco de Mayo Trivia Questions
Interactive video
•
3rd - 5th Grade
17 questions
HCS Grade 4 Simulation Assessment_2 2526sy
Quiz
•
4th Grade
24 questions
HCS Grade 5 Simulation Assessment_2 2526sy
Quiz
•
5th Grade
13 questions
Cinco de mayo
Interactive video
•
6th - 8th Grade
20 questions
Math Review
Quiz
•
3rd Grade
30 questions
GVMS House Trivia 2026
Quiz
•
6th - 8th Grade