Java Programming Questions and Answers Set 15

Java Programming OOPs

Questions 141 to 150


141.
The code fragment:
char ch = ' ';
try {
ch = (char) System.in.read();
while( (ch >= 'A') && (ch <= 'Z'))
ch = (char) System.in.read();
} catch (Exception e) {
System.out.println("error found.");
}
can be expressed equivalently as:
(a)
char ch = ' ';
try {
do {
ch = (char) System.in.read();
} while ( (ch >= 'A') && (ch <= 'Z'));
} catch (Exception e) {
System.out.println("error found.");
}
(b)
char ch = ' ';
try {
do {
ch = (char) System.in.read();
} while ( (ch >= 'A') || (ch <= 'Z'));
} catch (Exception e) {
System.out.println("error found.");
}
(c)
char ch = ' ';
try {
do {
ch = (char) System.in.read();
} while ( (ch < 'A') && (ch > 'Z'));
} catch (Exception e) {
System.out.println("error found.");
}
(d)
char ch = ' ';
try {
do {
ch = (char) System.in.read();
} while ( (ch < 'A') || (ch > 'Z'));
} catch (Exception e) {
System.out.println("error found.");
}
(e)
char ch = ' ';
try {
do {
ch = (char) System.in.read();
} while ( (ch <= 'A') || (ch >= 'Z'));
} catch (Exception e) {
System.out.println("error found.");
}.
142.
What will the following program print when it is executed?
public class Practice11 {
public static void main(String args[]) {
int i = 0;
while (i < 3) {
if( i++ == 0 ) System.out.print("Merry");
if( i == 1) System.out.print("Merr");
if( ++i == 2) System.out.print("Mer");
else System.out.print("Oh no!");
}
}
}
(a)
Merry
Merr
Mer
(b)
MerryMerrMerOh no!
(c)
MerrMerOh no!
(d)
MerryMerrMerOh no!
MerrMerOh no!
MerOh no!
(e)
Merry.
143.
Which of the following is true?
(a)
Any applet must be an instance of java.awt.Applet.
(b)
You must always provide a no-arg constuctor for an applet.
(c)
You must always provide a main method for an applet.
(d)
You must always override the init method in an applet.
(e)
You must always overload the init method in an applet.
144.
Which method that executes immediately after the init () method in an applet?
(a)
destroy()
(b)
start()
(c)
stop()
(d)
run()
(e)
exit().
145.
When you run an applet, which of the following is invoked first?
(a)
The init method
(b)
The applet's default constructor
(c)
The stop method
(d)
The destroy method
(e)
Start method.
146.
When you run the following applet from a browser, what is displayed?
import javax.swing.*;
public class Test extends JApplet {
public Test() {
System.out.println("Default constructor is invoked");
}
public void init() {
System.out.println("Init method is invoked");
}
}
(a)
Default constructor is invoked, then Init method is invoked
(b)
Init method is invoked, then Default constructor is invoked
(c)
Default constructor is invoked
(d)
Init method is invoked
(e)
Default constructor is invoked twice.
147.
What must A method declare to throw?
(a)
Unchecked exceptions
(b)
Checked exceptions
(c)
Error
(d)
RuntimeException
(e)
Compliation exception.
148.
What information may be obtained from a ResultSetMetaData object?
(a)
Database URL and product name
(b)
JDBC driver name and version
(c)
Number of columns in the result set
(d)
Number of rows in the result set
(e)
Number of tables in the database.
149.
Which of the following statements is true?
(a)
You may load multiple JDBC drivers in a program.
(b)
You may create multiple connections to a database.
(c)
You may create multiple statements from one connection.
(d)
You can send queries and update statements through a Statement object.
(e)
All of the above.
150.
Which is a special file that contains information about the files packaged in a JAR file?
(a)
Class file
(b)
Source file
(c)
Text file
(d)
Manifest file
(e)
Image file.

Answers


141.
Answer : (a)
Reason  :       Know the difference between while() and do--while(). Also, make sure you know the syntax of do--while().
142.
Answer : (b)
Reason  :       This program exercises your ability to walk through if() statements as well as post and pre increment. Be sure to carefully walk through the code and don't forget the while() loop.
143.
Answer : (a)
Reason  :       Any applet must be an instance of java.awt.Applet except this statement remaining all are false.
144.
Answer : (b)
Reason  :       start() method  that executes immediately after the init() method in an applet
145.
Answer : (b)
Reason  :       When the applet is loaded to the Web browser, the Web browser creates an instance of the applet by invoking the applet?s default constructor.
146.
Answer : (a)
Reason  :       When the applet is loaded to the Web browser, the Web browser first creates an instance of the applet by invoking the applet?s default constructor, and then invokes the init() method
147.
Answer : (b)
Reason  :       A method must declare to throw checked options.
148.
Answer : (c)
Reason  :       Number of columns in the resultset information may be obtained from a ResultSetMetaData object.
149.
Answer : (e)
Reason  :       All the given statements are with respect to JDBC.
150.
Answer : (d)
Reason  :       Manifest file  is  a special file that contains information about the files packaged in a JAR file


<< Prev   1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22  

 23   24   25   26   27   28   29   30  Next >>


1 comment :