OBJECT ORIENTED PROGRAMMING WITH JAVA
Assignment12
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10× 1 = 10
______________________________________________________________________________
QUESTION 1:
Which statement is true in case of using “this” keyword in a static method?
a. “this” keyword can be used in static method to access static variables only
b. “this” keyword can't be used in static method
c. “this” keyword can be used in static method
d. None
Correct Answer: a
________________________________________________________________________
QUESTION 2:
State whether the following statements are True or False.
i) A catch can have comma-separated multiple arguments.
ii) Throwing an Exception always causes program termination.
a. True, False
b. False, True
c. True, True
d. False, False
Correct Answer: d
Detailed Solution:
_________________________________________________________________
QUESTION 3:
Which of the following contains both date and time?
a) java.io.date
b) java.sql.date
c) java.util.date
d) java.util.dateTime
Answer: c
Explanation: java.util.date contains both date and time. Whereas, java.sql.date contains
only date.
______________________________________________________________________________
QUESTION 4:
In Graphics class which method is used to draws a rectangle with the specified width and
height?
a) public void drawRect(int x, int y, int width, int height)
b) public abstract void fillRect(int x, int y, int width, int height)
c) public abstract void drawLine(int x1, int y1, int x2, int y2)
d) public abstract void drawOval(int x, int y, int width, int height)
ANSWER: a
___________________________________________________________________
QUESTION 5:
Which of the following control expressions are valid for an if statement?
a. Any integer expression.
b. Any Boolean expression.
c. A String object.
d. Any expression with mixed arithmetic.
Correct Answer: b
Detailed Solution:
In Java if accepts only boolean expression
____________________________________________________________________________
QUESTION 6:
Consider the following program:
What is the output of the Java program given above?
A) No output
B) GOAT
C) DOMESTIC
D) Compiler error
Answer D
Explanation:
Case statements should start with either "case" or "default" only.
_____________________________________________________________________________
QUESTION 7:
Consider the following program:
What is the output of the following program?
a. java
b. ava
c. y java
d. january
Correct Answer: b
Detailed Solution:
______________________________________________________________________________
QUESTION 8:
Which of the following statements would cause a compilation error?
a. float[] = new float(3);
b. float f2[] = new float[];
c. float[] f1 = new float[3];
d. float f3[] = new float[3];
e. float f5[]={ 1.0f, 2.0f, 2.0f };
f. float f4[] = new float[] { 1.0f, 2.0f, 3.0f};
Correct Answer: a, b
Detailed Solution:
Option (c), (d), (e) and (f) are syntactically correct for declaration of an array. (a), (b) will cause
error.
______________________________________________________________________________
QUESTION 9:
Consider the following piece of code in Java.
public class Test {
public static void aMethod() throws Exception {
try {
throw new Exception();
}
finally {
System.out.print(“finally ”);
}
}
public static void main(String args[]){
try {
aMethod();
}
catch (Exception e) {
System.out.print(“exception ”);
} finally {
System.out.print(“finally ”);
}
System.out.print(“finished ”);
}
}
What is the result, if the above-mentioned program is executed?
a. finally
b. finally exception finally finished
c. finally exception finished
d. Compilation fails
Correct Answer: b
Detailed Solution:
The program is syntactically correct and here for two try blocks.
______________________________________________________________________________
QUESTION 10:
Which is a component in AWT that can contain another components like buttons,
textfields, labels etc.?
A) Window
B) Container
C) Panel
D) Frame
Correct Answer: B
Detailed Solution:
The Container is a component in AWT that can contain another components like buttons,
textfields, labels etc. The classes that extends Container class are known as container such as
Frame, Dialog and Panel.
______________________________________________________________________________
************END************