Object Oriented Programming With Java Assignment 12
Object Oriented Programming With Java Assignment 12
QUESTION 1:
Which of the following control expression is valid for an if statement in Java?
a. Any integer expression.
b. Any Boolean expression.
c. A String object.
d. Any expression with mixed arithmetic.
Correct Answer: b
Detailed Solution:
Java only supports Boolean datatype in if statement.
_________________________________________________________________________
QUESTION 2:
Consider the following class definition:
class Student extends String {
Correct Answer: c
Detailed Solution:
One cannot extend a class which is declared as final. The java.lang.String class is final.
_________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 3:
Which of the following cannot protect a class (non sub-class) in a package from accessibility by
the class outside the package?
a. private
b. protected
c. public
d. default
Correct Answer: c
Detailed Solution:
The private access modifier makes a class private in the sense that the methods or data members
are accessible only within the class in which they are declared. Any other class of same package
(or in other package) will not be able to access these members. In other words, private means
“only visible within the enclosing class”. If a class is declared as protected, then only different
package non-subclass is unaccesssable. The default class is accessible within the same package
only. Only public gives the freedom of accessibility everywhere.
______________________________________________________________________________
QUESTION 4:
We would like to make a member of a class invisible in all sub classes regardless of what
package they are in. Which of the following keywords would achieve this?
a. public
b. private
c. protected
d. final
Correct Answer: b
Detailed Solution:
A private member is not accessible to any sub-class, whether it is within the same package or
different package.
______________________________________________________________________________
QUESTION 5:
Which of the following is/ are reserved keyword(s)?
a. switch
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
b. string
c. Boolean
d. this
Correct Answer: a, d
Detailed Solution:
In Java, boolean and String are reserved keywords. Since the Java language is case sensitive
string and Boolean are different from String and boolean, respectively.
____________________________________________________________________________
QUESTION 6:
Which of the following method(s) belong(s) to the String class?
a. length()
b. compareTo()
c. equals()
d. substring()
e. All of them
Correct Answer: e
Detailed Solution:
Consult the String class in java.lang package ( https://docs.oracle.com/javase/7/docs/api/ ) to see
what are the methods there.
_____________________________________________________________________________
QUESTION 7:
Consider the following piece of code in Java.
a. i=3
b. The program will not be able to compile successfully.
c. A ClassCastException is thrown at line 6
d. A ClassCastException is thrown at line 7
Correct Answer: a
Detailed Solution:
Class Object is a super class of any class and any subclass object can be up casted to its
superclass object, hence line 6 and 7 executes without error.
______________________________________________________________________________
QUESTION 8:
Which of the following statements would not cause a compiler error?
Correct Answer: c, d, e, f
Detailed Solution:
Option (c), (d), (e) and (f) are syntactically correct to declare an array.
______________________________________________________________________________
QUESTION 9:
Consider the following piece of code in Java.
aMethod();
}
catch (Exception e) {
System.out.print(“exception ”);
}
System.out.print(“finished ”);
}
}
Correct Answer: c
Detailed Solution:
The program is syntactically correct and here for two try blocks, there is one catch block.
______________________________________________________________________________
QUESTION 10:
Consider the following piece of code in Java.
class A {
protected int method1 (int a, int b){
return 0;
}
}
Which of the following are are valid in a class that extends class A?
}
e. static protected int method1(int a, int b) {
return 0;
}
Correct Answer: b
Detailed Solution:
A protected member in super class become private member in its sub class. Anyway, as the
method polymorphism, all of the above except (e) are valid.
______________________________________________________________________________
QUESTION 11:
Consider the following piece of code in Java.
c. The program prints pairs of values for x and y that are always the same on the same line (for
example, “x = 1, y = 1”)
d. In addition, each value appears only once (for example, “x = 1, y = 1” followed by “x = 2, y =
2” and so on). The thread name at the start of the line shows that only a single thread is
actually executing.
Correct Answer: c
Detailed Solution:
Here, two threads will run concurrently and as they are synchronized so print will be in that
order. However, order of printing may be arbitrary.
______________________________________________________________________________
QUESTION 12:
Which of the following statement is correct?
a. The appletviewer can run any file irrespective of the file extension as .htm.
b. The CheckboxGroup class is a subclass of the Component which is defined in the java.io
package.
c. The CODE value in an <APPLET> tag must name a class file that is in the same
directory as in the calling directory.
d. An applet can contain a component Frame.
Correct Answer: a
Detailed Solution:
Note: ChckboxGroup is defined in java.awt package. For an applet, the .clss file can be
anywhere and an applet cannot contain a frame.
______________________________________________________________________________
QUESTION 13:
Which of the statements are correct about Swing programming?
Correct Answer: c
Detailed Solution:
Swing is lightweight compared to the AWT.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
______________________________________________________________________________
QUESTION 14:
What is the use of Socket and ServerSocket??
a. The class Socket is used to run two programs in two different machines and then
communicate each other.
b. The class Socket is used to run two programs in the same machines and then
communicate each other.
c. The class ServerSocket is used to run two programs in two different machines and then
communicate each other.
d. The class ServerSocket is used to run a program in a machine and then listen to other
programs defined with Socket class.
Correct Answer: d
Detailed Solution:
The ServerSocket and Socket are the classes used to build Client-Server systems.
______________________________________________________________________________
QUESTION 15:
Execution of SQL command like SELECT * FROM myTable using JDBC program will return a
ResultSet object. This object is
Correct Answer: b
Detailed Solution:
The ResultSet object includes all records stored as an array of records and irrespective of
whether a record contains null value(s) or not.
______________________________________________________________________________
************END************