Repository navigation
Expand file tree
/
Copy pathch2_firstjavaprogram.ptx
More file actions
701 lines (612 loc) · 32.4 KB
/
Copy pathch2_firstjavaprogram.ptx
File metadata and controls
701 lines (612 loc) · 32.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
<chapter xml:id="java-programs">
<title>Java Programs</title>
<section xml:id="first-java-program">
<title>First Java Program</title>
<p>
A time-honored tradition in computer science is to write a program called "hello world". The "hello world" program is simple and easy.
There are no logic errors to make, so getting it to run relies only on understanding the syntax.
</p>
<program interactive="activecode" language="python">
<code>
print ("Hello World!")
</code>
<tests> </tests>
</program>
<p>
Next, let's look at a more "complicated" version of hello world for Python:
</p>
<program interactive="activecode" language="python">
<code>
def main():
print ("Hello World!")
main()
</code>
<tests> </tests>
</program>
<p>
This is a bit more complicated, but it is still very simple. We have defined a function called <c>main</c> and then we call that function.
Java code will look more like this more complicated version of <c>hello world</c> than the simpler version.
</p>
<p>
Now lets look at the same program written in Java:
</p>
<program interactive="activecode" language="java">
<code>
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
</code>
<tests> </tests>
</program>
<p>
What we see is that at the core there are a few similarities, such as a <c>main</c> and the string "Hello World". However, there is a lot more stuff around the edges that make it harder to see the core of the program. Do not worry! An important skill for a computer scientist is to learn what to ignore and what to look at carefully. You will soon find that there are some elements of Java that will fade into the background as you become used to seeing them.
</p>
<p>
<term>What This Means for You:</term>
Coming from Python, you'll notice that Java is more "verbose" - you write more to say the same thing.
Java catches type errors before your program runs (this is actually helpful!).
Java's structure is more rigid, but this makes large programs easier to maintain.
The extra syntax becomes natural with practice.
</p>
<p>
<term>What Stays the Same:</term>
The core programming concepts you already know - <c>if-else</c> logic, <c>for</c> and <c>while</c> loops, variables, and functions, all work similarly in Java.
You're not re-learning how to program again, you are just learning a new way to express the same ideas.
</p>
<subsection xml:id="compiling-and-running">
<title>Compiling and Running Java Programs</title>
<p>
<idx>interpreter</idx>
<idx>interpreted language</idx>
<idx>compile</idx>
A natural question that you may have about this little program is "How would I run it on my own computer?" Running a Java program on your computer is not as simple as running a Python program because the first thing you need to do with a Java program is to compile it, which is not needed in Python. Python is an <term>interpreted language</term>. We could run our Python programs in the Python <term>interpreter</term> and we can be quite happy to do only that. Java makes running programs a two-step process. First, we must type the hello world program into a file and save that file using the filename <c>Hello.java</c> because the file name must be the same as the public class that you define in the file. Once we have saved the file, we <term>compile</term> it either in our IDE or from the command line as follows:
</p>
<program language="java">
<code>
$ javac Hello.java
$ ls -l Hello.*
-rw-r--r-- 1 bmiller bmiller 391 Jul 19 17:47 Hello.class
-rw-r--r-- 1 bmiller bmiller 117 Jul 19 17:46 Hello.java
</code>
</program>
<p>
<idx>byte code</idx>
<idx><c>javac</c></idx>
The command <c>javac</c> compiles our Java source code into compiled <term>byte code</term> and saves it in a file called <c>Hello.class</c>.
<c>Hello.class</c> is a binary file, so you won't learn much if you try to examine the class file with an editor.
Hopefully you didn't make any mistakes, but if you did you may want to consult the <xref ref="common-mistakes"/> section for helpful hints on compiler errors.
</p>
<p>
Now that we have compiled our Java source code we can run the compiled code using the <c>java</c> command.
</p>
<program language="java">
<code>
$ java Hello
Hello World!
$
</code>
</program>
<p>
Now you may be wondering what good is that extra step? What does compiling do for us? There are a couple of important benefits we get from compiling:
</p>
<p>
<ul>
<li>
<p>
Early detection of errors
</p>
</li>
<li>
<p>
Faster program execution
</p>
</li>
</ul>
</p>
<p>
<idx>JVM</idx><idx>Java Virtual Machine</idx>
<idx>byte code</idx>
The job of the compiler is to turn your java code into language that the <term>Java virtual machine</term> (<term>JVM</term>) can understand.
We call the code that the JVM understands <term>byte code</term>.
The JVM interprets the byte code much like the Python interpreter interprets your Python.
However since byte code is much closer to the native language of the computer it can run faster.
</p>
<p>
When the compiler does the translation it can find many different kinds of errors.
For example, if you make a typo, the compiler will find the typo and point it out to you before you ever run the program.
We will look at some examples of compiler errors shortly.
Chances are you will create some on your own very soon, too.
</p>
</subsection>
</section>
<section xml:id="key-language-differences">
<title>Key Language Differences</title>
<p>
Now that you've seen your first Java program, let's examine the key differences between Java and Python more systematically. Some differences can be immediately observed in their syntax and structure.
</p>
<table xml:id="python-vs-java-key-differences">
<title>Python vs Java: Key Differences</title>
<tabular>
<row bottom="minor">
<cell><term>Aspect</term></cell>
<cell><term>Python</term></cell>
<cell><term>Java</term></cell>
</row>
<row>
<cell><term>Variable Declaration</term></cell>
<cell><c>x = 5</c></cell>
<cell><c>int x = 5;</c></cell>
</row>
<row>
<cell><term>Code Blocks</term></cell>
<cell>Indentation (tabs/spaces)</cell>
<cell>Curly braces <c>{ }</c></cell>
</row>
<row>
<cell><term>Line Endings</term></cell>
<cell>Optional</cell>
<cell>Semicolons <c>;</c> required</cell>
</row>
<row>
<cell><term>Type Checking</term></cell>
<cell>Dynamic (runtime)</cell>
<cell>Static (compile time)</cell>
</row>
</tabular>
</table>
<p>
The above differences are easy to identify and understand, but there are some more subtle differences that will take a bit more time to grasp. The most important of these is how Java organizes all code around classes and objects which we will cover in the next section.
</p>
<subsection xml:id="understanding-java-structure">
<title>Understanding the Structure</title>
<p>
But, before we move on, let's go back and look at our Hello World program carefully to see what we can learn about the Java language.
This simple example illustrates a few very important rules:
</p>
<p>
<ol marker="1">
<li>
<p>
Every Java program must define a class, and all code is inside a class
</p>
</li>
<li>
<p>
Everything in Java must have a type
</p>
</li>
<li>
<p>
Every Java program must have a function called <c>public static void main(String[] args)</c>
</p>
</li>
</ol>
</p>
<p>
Let's take the hello world example a line at a time to see how these rules are applied.
On line 1 we see that we are declaring a class called Hello:
</p>
<program language="java">
<code>
public class Hello {
</code>
</program>
<p>
<idx>code blocks</idx>
<idx>curly braces</idx>
As rule 1 says all Java code resides inside a class.
Unlike Python where a program can simply be a bunch of statements, Java programs must be inside a class.
So, we define a class <c>Hello</c>, which is not a very useful class because it has no instance variables, and only one method.
You will also notice the <term>curly brace</term> <c>{</c>.
In Java, <term>blocks of code</term> are identified by pairs of curly braces.
The block starts with a <c>{</c> and ends with a <c>}</c>.
You will notice that I indented my code that followed the left brace, but in Java this is only done by convention, it is not enforced.
</p>
<p>
On the next line we start our method definition.
The name of this method is:
</p>
<program language="java">
<code>
public static void main(String[] args)
</code>
</program>
<note>
<title>Why So Much Detail in main?</title>
<p>
Every part of <c>public static void main(String[] args)</c> is required and meaningful. We'll explore what <c>public</c>, <c>static</c>, and <c>void</c> mean as we go, but for now, just know this exact signature is required for Java programs to run.
</p>
</note>
<p>
We're covering a lot of syntax details here - don't worry about memorizing everything! The goal is to understand the overall structure and know that Java is more explicit about types and method signatures than Python.
</p>
<p>
Just digging in to this one line will take us deep into the world of Java, so we are going to start digging but we are not going to dig too deeply right away.
Much of what could be revealed by this one line is better understood through other examples, so be patient.
</p>
<p>
<idx><c>public</c></idx>
<idx><c>protected</c></idx>
<idx><c>private</c></idx>
The first word, <term>public</term> indicates to the Java compiler that this is a method that anyone can call.
We will see that Java enforces several levels of security on the methods we write, including public, <term>protected</term>, and <term>private</term> methods.
</p>
<p>
<idx><c>static</c></idx>
The next word, <term>static</term> tells Java that this is a method that is part of the class, but is not a method for any one instance of the class.
The kind of methods we typically wrote in Python required an instance in order for the method to be called.
With a static method, the object to the left of the <c>.</c> is a class, not an instance of the class.
For example, the way that we would call the <c>main</c> method directly is: <c>Hello.main(parameter1)</c>.
For now, you can think of static methods the same way you think of methods in Python modules that don't require an instance, for example the math module contains many methods: sin, cos, etc.
You probably evaluated these methods using the names <c>math.cos(90)</c> or <c>math.sin(60)</c>.
</p>
<p>
<idx><c>void</c></idx>
The next word, <term>void</term> tells the Java compiler that the method <c>main</c> will not return a value.
This is roughly analogous to omitting the return statement in a Python method.
In other words, the method will run to completion and exit but will not return a value that you can use in an assignment statement.
As we look at other examples we will see that every Java function must tell the compiler what kind of an object it will return.
This is in keeping with the rule that says everything in Java must have a type.
In this case we use the special type called <c>void</c> which means no type.
</p>
<p>
<idx><c>main</c></idx>
Next we have the proper name for the method: <term>main</term>.
The rules for names in Java are similar to the rules in Python.
Names can include letters, numbers, and the <c>_</c>.
Names in Java must start with a letter.
</p>
<p>
<idx>array</idx>
Finally, we have the parameter list for the method.
In this example we have one parameter.
The name of the parameter is <c>args</c>, however, because everything in Java must have a type, we also have to tell the compiler that the value of <c>args</c> is an <term>array</term> of strings.
For the moment you can just think of an array as being the same thing as a list in Python.
The practical benefit of declaring that the method <c>main</c> must accept one parameter and the parameter must be an array of strings is that if you call <c>main</c> somewhere else in your code and and pass it an array of integers or even a single string, the compiler will flag it as an error.
</p>
<p>
That is a lot of new material to digest in only a single line of Java! Let's press on and look at the next line:
</p>
<program language="java">
<code>
System.out.println("Hello World!");
</code>
</program>
<p>
<idx>dot notation</idx>
This line should look a bit more familiar to you.
Python and Java both use the <term>dot notation</term> for finding names.
In this example we start with <c>System</c>.
System is a class.
Within the system class we find the object named <c>out</c>.
The <c>out</c> object is the standard output stream for this program.
Having located the <c>out</c> object Java will now call the method named <c>println(String s)</c> on that object.
The <c>println</c> method prints a string and adds a newline character at the end.
Anywhere in Python that you used the <c>print</c> function you will use the <c>System.out.println</c> method in Java.
</p>
<p>
Now there is one more character on this line that is significant and that is the <c>;</c> at the end.
In Java the <c>;</c> signifies the end of a statement.
Java statements can spread across many lines, but the compiler knows it has reached the end of a statement when it encounters a <c>;</c>.
In Python, it is not required (or recommend) to use semicolons in this way, but whitespace is meaningful.
In contrast, in Java semicolons are <term>required</term> to end statements, but whitespace is not considered meaningful.
</p>
<p>
The last two lines of the hello world program simply close the two blocks using <c>}</c>.
The first or outer block is the class definition.
The second or inner block is the function definition.
</p>
</subsection>
</section>
<section xml:id="classes-and-oop">
<title>Classes and Object-Oriented Programming</title>
<p>
<idx>class</idx>
<idx>object</idx>
<idx>object-oriented programming</idx>
<idx>OOP</idx>
If you've been programming in Python, you've likely worked with simple data types like numbers, strings, and lists, plus written functions to process them. Java takes a different approach by organizing code around <term>classes</term> and <term>objects</term> - a style called <term>Object-oriented programming</term> (<term>OOP</term>).
</p>
<p>
<idx>blueprint</idx>
<idx>template</idx>
<idx>methods</idx>
Think of a class like a blueprint or template. Just as a house blueprint shows what rooms a house should have and where they go, a class defines what information an object should store and what actions it can perform. For example, we might create a <c>Dog</c> class that stores a dog's name and breed, and includes methods like <c>bark()</c> and <c>sit()</c>.
</p>
<note>
<p>
If you've already worked with classes in Python, this will look familiar - the main difference is that Java requires ALL code to be inside classes, while Python makes classes optional.
</p>
</note>
<p>
The best way to understand classes and objects is to see them in action. Let's define a <c>Dog</c> class in Python:
</p>
<program language="python" xml:id="python-class-example">
<code>
class Dog:
def __init__(self, name, breed, fur_color):
self.name = name
self.breed = breed
self.fur_color = fur_color
self.trained = False
print("Dog named " + self.name + " created!")
def bark(self):
print(self.name + " says woof!")
def sit(self):
if self.trained:
print(self.name + " sits.")
else:
print(self.name + " has not been trained.")
def train(self):
self.trained = True
</code>
</program>
<p>
<idx>initializer</idx>
<idx>constructor</idx>
Let's unpack what is going on in this code. The first line is where we declare the class definition and name it <c>Dog</c>. Next, we have a special method called <c>__init__</c>. This <c>__init__</c> method is the <term>initializer</term> or <term>constructor</term>, and it is required for every Python class definition. Within the <c>__init__</c> method, attributes are defined. As you can see, the attributes <c>name</c>, <c>breed</c>, and <c>fur_color</c> must be defined when creating a <c>Dog</c> object using this class definition, but the <c>trained</c> attribute is defined within the constructor and is initialized as <c>False</c>. We can also have the <c>__init__</c> method run any code, such as the print statement informing us that a Dog object was created, which we're including here just for demonstration purposes.
</p>
<p>
The next three blocks of code are the class's methods. These include <c>bark(self)</c>, <c>sit(self)</c>, and <c>train(self)</c>. As you can see, the class defines attributes (the variables in the <c>__init__</c> method) and methods for instances of the Dog class.
</p>
<p>
<idx><c>self</c></idx>
Within each method, and for each attribute, you will notice the use of <term><c>self</c></term>. This is required in Python. The <c>self</c> parameter simply indicates that an attribute or method is being used for a specific instance of an object created with a class.
</p>
<p>
Next, we will use this class to create a new <c>Dog</c> object. We will call this new <c>Dog</c> object <c>my_dog</c>:
</p>
<program interactive="activecode" language="python" xml:id="python-class-create-object">
<code>
class Dog:
def __init__(self, name, breed, fur_color):
self.name = name
self.breed = breed
self.fur_color = fur_color
self.trained = False
print("Dog named " + self.name + " created!")
def bark(self):
print(self.name + " says woof!")
def sit(self):
if self.trained:
print(self.name + " sits.")
else:
print(self.name + " has not been trained.")
def train(self):
self.trained = True
my_dog = Dog("Rex", "pug", "brown")
</code>
</program>
<p>
In the final line of code, we have created an object called <c>my_dog</c>. We have initialized its attributes, setting <c>name</c> to Rex, <c>breed</c> to pug, and <c>fur_color</c> to brown.
</p>
<p>
Now that we have created a <c>Dog</c> object using the class we defined, we can utilize the class's methods:
</p>
<program interactive="activecode" language="python" xml:id="python-class-full">
<code>
class Dog:
def __init__(self, name, breed, fur_color):
self.name = name
self.breed = breed
self.fur_color = fur_color
self.trained = False
print("Dog named " + self.name + " created!")
def bark(self):
print(self.name + " says woof!")
def sit(self):
if self.trained:
print(self.name + " sits.")
else:
print(self.name + " has not been trained.")
def train(self):
self.trained = True
my_dog = Dog("Rex", "pug", "brown")
my_dog.bark()
my_dog.sit()
</code>
</program>
<question>
<p>
When running the code above, the line <c>Rex has not been trained.</c> will appear in the output when calling the <c>sit()</c> method. Try adding a one or more lines of code so that <c>Rex sits.</c> appears in the output!
</p>
</question>
<p>
Now, we have a full class definition and have utilized its methods. Class definitions in Java will be covered thoroughly in chapter 6. For now, it is important to know that Python programs can be written without using classes at all. Java, on the other hand, requires all code to reside in a class. This will be discussed in the next section.
</p>
<p>
Later in this text, we will see how to make our own Java classes that are similar to the Python <c>Dog</c> class that we just defined. See <xref ref="defining-classes-in-java" /> for more details.
</p>
</section>
<section xml:id="lets_look_java_program_summary">
<title>Summary & Reading Questions</title>
<p>
<ol label="1">
<li>
<p>Java programs must be compiled before execution, unlike Python which is interpreted directly.</p>
</li>
<li>
<p>Every Java program must define a <c>class</c>, and all code must be inside that class.</p>
</li>
<li>
<p>Each Java program must include a <c>public static void main(String[] args)</c> method as the entry point.</p>
</li>
<li>
<p>Java enforces that every variable and method must have a clearly defined type, including <c>void</c> for methods that return nothing.</p>
</li>
<li>
<p>Statements in Java must end with a semicolon (<c>;</c>), and whitespace is not syntactically meaningful.</p>
</li>
<li>
<p>Java uses dot notation to access class members, such as <c>System.out.println</c> for output.</p>
</li>
<li>
<p>The <c>static</c> keyword indicates that a method belongs to the class itself, rather than to an instance of the class.</p>
</li>
<li>
<p>Object-oriented programming organizes code around classes (blueprints) and objects (instances of classes).</p>
</li>
</ol>
</p>
<reading-questions xml:id="rqs-hello-java">
<exercise label="hello-java-1">
<statement>
<p>Which of the following must be true of every Java program?</p>
</statement>
<choices>
<choice>
<statement>
<p>It must contain a method called <c>main()</c> with no parameters.</p>
</statement>
<feedback>
<p>No. The main method must include a specific parameter: <c>String[] args</c>.</p>
</feedback>
</choice>
<choice correct="yes">
<statement>
<p>It must include a <c>public static void main(String[] args)</c> method inside a class.</p>
</statement>
<feedback>
<p>Correct! This is the required entry point for all Java applications.</p>
</feedback>
</choice>
<choice>
<statement>
<p>It must be saved with a <c>.exe</c> extension.</p>
</statement>
<feedback>
<p>No. Java source files use the <c>.java</c> extension and compile to <c>.class</c>.</p>
</feedback>
</choice>
<choice>
<statement>
<p>It must be run using the Python interpreter.</p>
</statement>
<feedback>
<p>No. Java uses its own compiler and Java Virtual Machine (JVM).</p>
</feedback>
</choice>
</choices>
</exercise>
<exercise label="hello-java-2">
<statement>
<p>What is the purpose of the <c>javac</c> command?</p>
</statement>
<choices>
<choice correct="yes">
<statement>
<p>To compile Java source code into bytecode</p>
</statement>
<feedback>
<p>Exactly! <c>javac</c> compiles <c>.java</c> files into <c>.class</c> files.</p>
</feedback>
</choice>
<choice>
<statement>
<p>To run a Python program</p>
</statement>
<feedback>
<p>No. Python programs are run with the <c>python</c> or <c>python3</c> command.</p>
</feedback>
</choice>
<choice>
<statement>
<p>To debug Java programs</p>
</statement>
<feedback>
<p>No. <c>javac</c> only compiles code. Debugging is a separate process.</p>
</feedback>
</choice>
<choice>
<statement>
<p>To edit Java source files</p>
</statement>
<feedback>
<p>No. You use a text editor or IDE to edit Java files.</p>
</feedback>
</choice>
</choices>
</exercise>
<exercise label="hello-java-3">
<statement>
<p>What symbol does Java use to indicate the end of a statement?</p>
</statement>
<choices>
<choice>
<statement>
<p><c>#</c></p>
</statement>
<feedback>
<p>No. <c>#</c> is used for comments in Python, not for statement termination.</p>
</feedback>
</choice>
<choice correct="yes">
<statement>
<p><c>;</c></p>
</statement>
<feedback>
<p>Correct! Java uses semicolons to mark the end of a statement.</p>
</feedback>
</choice>
<choice>
<statement>
<p><c>.</c></p>
</statement>
<feedback>
<p>No. <c>.</c> is used for dot notation, not to end a statement.</p>
</feedback>
</choice>
<choice>
<statement>
<p><c>}</c></p>
</statement>
<feedback>
<p>No. <c>}</c> is used to close code blocks.</p>
</feedback>
</choice>
</choices>
</exercise>
<exercise label="hello-java-4">
<statement>
<p>In object-oriented programming, what is a class?</p>
</statement>
<choices>
<choice correct="yes">
<statement>
<p>A blueprint or template for creating objects</p>
</statement>
<feedback>
<p>Exactly! A class defines the structure and behavior that objects will have.</p>
</feedback>
</choice>
<choice>
<statement>
<p>A specific instance of an object</p>
</statement>
<feedback>
<p>No. That describes an object, not a class.</p>
</feedback>
</choice>
<choice>
<statement>
<p>A method that creates variables</p>
</statement>
<feedback>
<p>No. A class is not a method.</p>
</feedback>
</choice>
<choice>
<statement>
<p>A type of loop structure</p>
</statement>
<feedback>
<p>No. Classes are not related to loop structures.</p>
</feedback>
</choice>
</choices>
</exercise>
</reading-questions>
</section>
</chapter>