Question: 1) Write Java code that will declare and create a Scanner object named in to read from an input file named in.txt . Write code
1) Write Java code that will declare and create a Scanner object named in to read from an input file named in.txt. Write code so that should a FileNotFoundException occur, the code shall handle the exception by displaying an error message that in.txt could not be opened for reading and immediately terminate the program by calling System.exit(-1).
2)
Assume a PrintWriter object named out which writes to a file named out.txt has been declared and created (the file is opened for writing). Write Java code that will write the even integers in list3 to out.txt. Hint: an integer is even if after dividing it by 2 you get a remainder of 0. For the sample in.txt file, the contents of out.txt will be:
Sample out.txt for given in.txt 4 6 8 0 2 6
30
Consider these classes. Write the Java code to implement both classes. The Workerconstructor shall call the Person constructor to initialize the mName instance variable of a Worker object.
4)
Suppose a class Super declares three instance variables:
(1) a protected int variable named mX;
(2) a private int variable named mY;
(3) a public int variable named mZ.
Class Sub is a direct subclass of Super. We instantiate a Subobject. Which of the Super instance variables are members of the Sub object?
| a- mZ | ||
| b- mX and mZ | ||
| c- mX, mY, and mZ | ||
| d- mY and mZ | ||
| e -mX and mY |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
