top of page

CIS043 current Final Exam and Solutions 2018

CIS043 Final Exam and Solutions
Get 90+ score securely in CIS043 Exam. -
Download Now 

Question 1
Assumming the variable q has been assigned the value 3, which of the following statements displays XXX?
   
if (q>0) System.out.println("XXX");
   
if (q>7); System.out.println("XXX);
   
Both of the above statements display XXX.
 
   
Neither of the above statements displays XXX.
 
 
Question 2
1 / 1 pts
Which of the following could be the last legally coded line of a method declared as public static int getVal(double sum)?
   
return;
 
   
return 77;
 
   
return 2.3;
 
   
Any of these could be the last coded line of the method
 
 
Question 3
1 / 1 pts
What is the output of the following Java code?

int[] list = {0, 5, 10, 15, 20};

for (int j = 0; j <list.length; j++)
   System.out.print(list[j] + " ");
System.out.println();
   
0 1 2 3 4
   
0 5 10 15 20
   
0, 5, 10, 15, 20
   
0 5 10  15
 
Question 4
3 + randomNumbers.nextInt(35) returns a random number __________.
   
between 1 and 35
 
   
between 3 and 35
 
   
between 3 and 38
 
   
between 3 and 37
 
 
Question 5
1 / 1 pts
public static char methodHeading(int n, double num)

Which of the following statements about the method heading in the accompanying figure is NOT true?
   
The method has two parameters.
 
   
The method cannot be used outside the class.
 
   
methodHeading is an identifier giving a name to this specific method.
   
It is a value-returning method of type char.
 
Question 6
1 / 1 pts
What type of methods allow a client of a class to assign values to a private instance variable?
   
Get methods.
   
Replace methods.
   
Assign methods.
   
Set methods.
 
Question 7
1 / 1 pts
What is the value of result after the following Java statements execute?
int a, b, c, d, result;
a = 4;
b = 12;
c = 38;
d = 51;
result = d % a * c/4 + (a/b - d/2); 
 
   
7
 
   
53
 
   
2
 
   
3
 
 
Question 8
1 / 1 pts
Which of the following should be defined as a void method?
   
Write a method that prints integers from 1 to 100.
 
   
Write a method that returns a random integer from 1 to 100.
 
  
Write a method that checks whether total quantity is an integer from 1 to 100.
   
Write a method that converts an uppercase letter to lowercase.
 
 
Question 9
1 / 1 pts
The name of the ____ is always the same as the name of the class whose objects it creates.
   
method
 
   
constructor
 
   
argument
 
   
variable
 
 
Question 10
1 / 1 pts
The following loop displays _______________.
for (int i = 1; i <= 10; i++) {
  System.out.print(i + "  ");
  i++;
}
 
   
1 2 3 4 5 6 7 8 9
 
   
1 2 3 4 5 6 7 8 9 10
 
   
1 2 3 4 5
 
   
1 3 5 7 9
 
   
2 4 6 8 10
 
 
Question 11
1 / 1 pts
When a method returns an array reference, you include ____ with the return type in the method header.
   
{ }
 
   
( )
 
   
< >
   
[ ]
 
 
Question 12
What is the result value of c at the end of the following code segment?
int c = 8; 
c++; 
++c; 
c %= 3;
   
0.
 
   
1.
 
   
2.
 
   
3.
 
 
Question 13
1 / 1 pts
Which of the following is incorrect? (Choose All that apply)
   
int[] a = new int[2];
 
   
int a() = new int[2];
 
   
int[] a = new int(2);
 
   
int a = new int[2];
 
 
Question 14
Which of the following println statements will display the last myScoreselement in an array of 10?
   
System.out.println(vals[0]);
   
System.out.println(vals[1]);
   
System.out.println(vals[9]);
   
System.out.println(vals[10]);
 
Question 15
1 / 1 pts
When an expression containing a ____ is part of an if statement, the assignment is illegal.
   
single equal sign
 
   
greater than sign
 
   
double equal sign
 
   
Boolean value
 
 
Question 16
1 / 1 pts
Which of the following statements starts a polygon named pol at the coordinates 20 and 290?
   
pol.moveTo(20F, 290F);
   
pol.lineTo(20F, 290F);
   
pol = new Path(20F, 290F);
   
pol.newPath(20F, 290F);
 
Question 17
1 / 1 pts
Usually, the subclass constructor only needs to initialize the ____ that are specific to the subclass.
   
objects
 
   
data fields
 
   
methods
 
   
constructors
 
 
Question 18
1 / 1 pts
Which of the following statements depicts the valid format to call a superclass constructor from a subclass constructor?
   
superclass(name, score);
   
subclass(name, score);
   
extends(name, score);
   
super(name, score);
 
Question 19
1 / 1 pts
Which of the following is used to allocate memory for the instance variables of an object of a class?
   
the reserved word public
   
the reserved word static
   
the operator new
   
the operator +
 
Question 20
1 / 1 pts
You specify 2D colors by using the ____ method.
   
paint()
   
setPaint()
   
color()
   
setColor()
 
Question 21
1 / 1 pts
The JCheckBox, JComboBox, and JRadioButton components are associated with the ____ method.
   
addAdjustmentListener()
   
addChangeListener()
   
addWindowListener()
   
addItemListener()
 
Question 22
1 / 1 pts
Which of the following is a valid statement? 
(i) int num = new int(67);
(ii) String name = new ("Doe");
(iii) String name = "Doe";
   
Only (i)
 
   
Only (i) and (ii)
 
   
Only (iii)
 
   
Only (ii) and (iii)
 
 
Question 23
1 / 1 pts
Which class contains the method for checking whether a file exists?
   
File
 
   
Formatter
 
   
Scanner
 
   
System
 
 
Question 24
1 / 1 pts
Which of the following most completely describes the steps for setting up event handling for a GUI component?
  
Create a class that represents the event handler, attach the JFrame to a JWindow object and register the event handler.
  
Implement an appropriate event-listener interface and register the event handler.
  
Create a class that represents the event handler and implement an appropriate event-listener interface.
  
Create a class that represents the event handler, implement an appropriate event-listener interface and register the event handler.
 
Question 25
Which of the following is not a method of the class JTextField?
   
setText
   
setEditable
   
addActionListener
   
setVisible
 
Question 26
___________ can be used to enter or display a string.
   
A label
 
   
A button
 
   
A check box
 
   
A radio button
 
   
A text field
 
 
Question 27
Suppose s is a string with the value "java". What will be assigned to x if you execute the following code? 
char x = s.charAt(4);
   
"a"
   
"v"
   
Nothing due to a runtime error StringIndexOutofBoundsException
 
   
"java"
 
Question 28
1 / 1 pts
Which method is used to register a listener object to a button object?
   
addActionListener
   
registerButton
   
eventButton
   
buttonListener
 
Question 29
1 / 1 pts
A method that executes because it is called automatically when an appropriate event occurs is an event ____.
   
responder
 
   
listener
 
   
handler
 
   
source
 
 
Question 30
1 / 1 pts
An attribute that is shared by all objects of the class is coded using _____________.
   
an instance variable
 
   
a static instance variable
 
   
an instance method
 
   
a static method
 
 
Question 31
1 / 1 pts
The compiler determines which version of a method to call by the method’s ____.
   
name
 
   
signature
 
   
output
 
   
constructor
 
 
Question 32
1 / 1 pts
MysteryClass
-first: int
-second: double;
+MysteryClass()
+MysteryClass(int)
+MysteryClass(double);
+MysteryClass(int, double)
+setData(int, double): void
+getFirst(): int
+getSecond(): double
+doubleFirst(): int
+squareSecond(): double
+print(): void
+equals(MysteryClass): boolean
+makeCopy(MysteryClass): void
+getCopy():MysteryClass

 

According to the UML class diagram in the accompanying figure, which method is public and doesn’t return anything?
   
getCopy()
   
print()
   
equals(MysteryClass)
   
doubleFirst()
 
Question 33
Given a Graphics object g, to draw an circle with radius 20 centered at (50, 50), you use __________.
   
g.drawOval(50, 50, 20, 20)
 
   
g.drawOval(50, 50, 40, 40)
 
   
g.drawOval(30, 30, 20, 20)
 
   
g.drawOval(30, 30, 40, 40)
 
 
Question 34
1 / 1 pts
Suppose that the class Mystery is derived from the class Secret. Consider the following statements.

Secret secRef = new Secret();
Mystery mysRef = new Mystery();

Which of the following statements is legal in Java?

(i)  secRef = mysRef;
(ii)  mysRef = secRef;
   
Only (i)
 
   
Only (ii)
 
   
Both (i) and (ii)
 
   
None of these
 
 
Question 35
Which class do you use to write data to a text file?
   
File
 
   
Formatter
 
   
Scanner
 
   
Input
 
 
Question 36
1 / 1 pts
MysteryClass
-first: int
-second: double;
+MysteryClass()
+MysteryClass(int)
+MysteryClass(double);
+MysteryClass(int, double)
+setData(int, double): void
+getFirst(): int
+getSecond(): double
+doubleFirst(): int
+squareSecond(): double
+print(): void
+equals(MysteryClass): boolean
+makeCopy(MysteryClass): void
+getCopy():MysteryClass

 

Which of the following would be a default constructor for the class MysteryClass shown in the accompanying figure?
   
public MysteryClass(){ setData(0, 0.0); }
   
public MysteryClass(0, 0.0) { setData(); }
   
public MysteryClass(0) { setData(0, 0.0); }
   
private MysteryClass(10){ setData(); }
 
Question 37
1 / 1 pts
The keyword ____ indicates that a field value is unalterable.
   
end
   
final
   
permanent
   
static
 
Question 38
1 / 1 pts
Exceptions can be thrown by:
   
the Java Virtual Machine.
 
   
code in a try block.
   
calls from a try block to other methods.
   
All of these.
 
 
Question 39
1 / 1 pts
Which of the following creates a color object? (Choose all that apply)
   
new Color(0, 0, 0)
 
   
new Color(0, 266, 0)
 
   
new Color(255, 255, 255)
 
   
new Color(1, 2, 3)
 
 
Question 40
1 / 1 pts
Which of the following is the method used to display a dialog box to gather input?
   
showMessageDialog.
   
getInput.
   
inputDialog.
   
showInputDialog.
 
Question 41
1 / 1 pts
Which of the following statements is true?
  
The class Exception, which is derived from the class Object, is the superclass of the class Throwable.
  
The class Throwable, which is derived from the class Exception, is the superclass of the class Object.
  
The class Throwable, which is derived from the class Object, is the superclass of the class Exception.
   
None of these
 
 
Question 42
1 / 1 pts
Suppose the String variable str points to the String object "Sunny day" at the memory address 3600. Then the value of str is: 
   
the memory address 3600
   
"Sunny day"
   
3600 + "Sunny day"
   
None of these
 
 
Question 43
1 / 1 pts
The methods in a subclass can use all of the data fields and methods that belong to its parent, with one exception: ____ members of the parent class are not accessible within a child class’s methods.
   
private
   
public
   
final
   
protected
 
Question 44
1 / 1 pts
When using the drawRoundRect() method, if you assign ____ to the arc coordinates, the rectangle is not rounded; instead, the corners are square.
   
-1
 
   
0
 
   
10
 
   
99
 
 
Question 45
1 / 1 pts
To create a window, which of the following classes has to be extended?
   
Container
   
JFrame
   
JButton
   
JTextField
 
Question 46
1 / 1 pts
The ____ method creates a solid arc.
   
solidArc()
   
fillArc()
   
clearArc()
   
drawArc()
 
Question 47
1 / 1 pts
When you create a class and do not provide a(n) ____, Java automatically supplies you with a default one.
   
constructor
 
   
argument
 
   
header
 
   
name
 
 
Question 48
1 / 1 pts
When you employ ____, your data can be altered only by the methods you choose and only in ways that you can control.
   
virtual method calls
 
   
polymorphism
 
   
information hiding
 
   
inlining
 
 
Question 49
1 / 1 pts
If a method throws an exception that it will not catch but that will be caught by a different method, you must also use the keyword ____ followed by an Exception type in the method header.
   
finally
   
try
   
catch
   
throws
 
Question 50
1 / 1 pts
The ActionListener interface contains the ____ method specification.
   
actionOccurred(Action e)
   
actionPerformed(ActionEvent e)
   
actionEvent(ActionEvent e)
   
action(Event e)

Download The CIS043 current Exam and Solutions

bottom of page