Skip to main content\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 4.2 ObjUse-WE1-P1
Subgoals for using objects (creating instances).
Declare variable of appropriate class datatype.
Assign to variable: keyword new, followed by class name, followed by ().
-
Determine whether parameter(s) are appropriate (API)
Number of parameters
Data types of the parameters
Subsection 4.2.1
Exercises Exercises
1.
Q1: Click on the variables (object references) in the following code
/* reads input from default - keyboard */
Scanner input = new Scanner(System.in);
/* reads input from InFile stream */
Scanner foo = new Scanner(InFile);
2.
Q2: Click on the class names (but not constructors) in the following code
/* reads input from default - keyboard */
Scanner input = new Scanner(System.in);
/* reads input from InFile stream */
Scanner foo = new Scanner(InFile);
3.
Q3: Click on the calls to the Scanner constructor in the following code
/* reads input from default - keyboard */
Scanner input = new Scanner(System.in);
/* reads input from InFile stream */
Scanner foo = new Scanner(InFile);
4.
Q4: Click on the parameters which are passed to the Scanner constructor in the following code
/* reads input from default - keyboard */
Scanner input = new Scanner(System.in);
/* reads input from InFile stream */
Scanner foo = new Scanner(InFile);
You have attempted
of
activities on this page.