File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 228228
229229 </p >
230230
231+ <exercise label =" java-new-keyword-checkpoint" >
232+ <statement >
233+ <p >
234+ Based on <xref ref =" new-keyword-error" text =" type-global" />, select all of the
235+ statements that are true about creating objects in Java.
236+ </p >
237+ </statement >
238+ <choices >
239+ <choice correct =" yes" >
240+ <statement >
241+ <p >Java requires the <c >new</c > keyword to create a new object.</p >
242+ </statement >
243+ <feedback >
244+ <p >Correct! Unlike Python, Java needs the <c >new</c > keyword to instantiate an object.</p >
245+ </feedback >
246+ </choice >
247+ <choice correct =" yes" >
248+ <statement >
249+ <p >Writing <c >data = new Scanner(new File("test.dat"));</c > would fix the error.</p >
250+ </statement >
251+ <feedback >
252+ <p >Correct! Adding <c >new</c > before <c >Scanner</c > properly creates the object and resolves the error.</p >
253+ </feedback >
254+ </choice >
255+ <choice correct =" yes" >
256+ <statement >
257+ <p ><c >Scanner</c > is a constructor of the <c >Scanner</c > class, not a standalone method.</p >
258+ </statement >
259+ <feedback >
260+ <p >Correct! Because <c >Scanner</c > is a constructor, it must be called with <c >new</c >.</p >
261+ </feedback >
262+ </choice >
263+ <choice >
264+ <statement >
265+ <p >Java can create objects without a keyword, just like Python.</p >
266+ </statement >
267+ <feedback >
268+ <p >Incorrect. Unlike Python, Java requires the <c >new</c > keyword to instantiate objects.</p >
269+ </feedback >
270+ </choice >
271+ <choice >
272+ <statement >
273+ <p >The "cannot find symbol" error here means the <c >Scanner</c > class was not imported.</p >
274+ </statement >
275+ <feedback >
276+ <p >Incorrect. The <c >Scanner</c > class is imported; the error is caused by the missing <c >new</c > keyword.</p >
277+ </feedback >
278+ </choice >
279+ </choices >
280+ </exercise >
281+
231282 </section >
232283
233284 <section xml : id =" forgetting-to-declare-the-kind-of-object-in-a-container" >
You can’t perform that action at this time.
0 commit comments