Java Programming Questions and Answers Set 17

Java Programming OOPs

Questions 161 to 170



161.
java server page is an extension of
(a)   html                  (b)  xml                   (c)  xhtml                 (d)  sgml             (e)  java servlet.
162.
Consider the following program while noting the missing variable declaration indicated by ?????? :
in the class Tree.
class Tree {
??????
Tree() {
treeNo++;
System.out.println("Tree "+ treeNo + " is created!"); }
}
public class Variable{
public static void main(String[] args) {
Tree t1 = new Tree();
Tree t2 = new Tree();
Tree t3 = new Tree(); }
}
The output of the above program should turn out to be as shown below:
Tree 1 is created!
Tree 2 is created!
Tree 3 is created!
Select from among the following the correct variable declaration required in the class Tree to get the above output on the console:
(a) int static treeNo = 0;                          (b) int treeNo;                                  (c) static int treeNo;
(d) static final int treeNo;                        (e) int treeNo = 0;
163.
Consider the following additional driver program:
public class Main {
public static void main(String[] args) {
ClassB b = new ClassB(1);
ClassC c = new ClassC(2);
}
}
Which of the following would the output be?
(a)   ClassA() constructor
ClassB(int) constructor
ClassA() constructor
ClassB(int) constructor
ClassC(int) constructor

(b)   ClassB(int) constructor
ClassA() constructor
ClassC(int) constructor
ClassB(int) constructor
ClassA() constructor
(c)   ClassA() constructor
ClassB(int) constructor
ClassB(int) constructor
ClassC(int) constructor
(d)   ClassB(int) constructor
ClassA() constructor
ClassC(int) constructor
ClassA() constructor
(e)   ClassB(int) constructor
ClassC(int) constructor

164.
What is the result of the expression 75.22 + “5.2”?
(a)   The double value in 80.42                (b)  The string in “80.42”.
(c)   The string is “75.225.2”                     (d)  The string is “75.222.5”
(e)   The long value is 80.
165.
Consider the following Java program to answer this Question:
public class Main {
private String s;
Main() {
this.print("Main() constructor");
}
static void print(String s) {
System.out.println(s);
this.s = s;
}
String getLastPrint() {
return s;
}
public static void main(String[] args) {
Main m = new Main();
m.print("Hello");
Main.print("Hello World");
String last = m.getLastPrint();
What would be the output of the above program if it is executed?
(a)   Hello
(b)   Hello World

(c)   Hello
Hello
Hello World
(d)   Hello
Hello World
Hello
(e) error
166.
Consider the following program written in Java to answer this Question:
01.class StringEx{
02.public static void main(String args[]) {
03.String s1="University of ICFAI”;
04.String s2="hello";
05.String s3="HELLO”;
06.System.out.println(s1.substring(10,13));
07.System.out.println(s2.equalsIgnoreCase(s3));
08.}
09.}
What would be the output of the statement indicated in line number 06 when the program is executed?
(a) University of ICFAI                            (b) error                                                 (c) of  
(d) Colombo                                          (e) ity.
167.
Consider the following program written in Java to answer this Question:
01.class StringEx{
02.public static void main(String args[]) {
03.String s1="University of ICFAI”;
04.String s2="hello";
05.String s3="HELLO”;
06.System.out.println(s1.substring(10,13));
07.System.out.println(s2.equalsIgnoreCase(s3));
08.}
09.}

What would be the output of the statement indicated in line number 07 when the program is executed?
(a) HELLO               (b) error                   (c) of                      (d) false                  (e) true.

168.
Consider the following program written in Java:
class User {
private String userName;
private int userType;
public void setUserName(String s) {
this.userName = s;
}
public void setUserType(int t) {
this.userType = t;
}
public String getUserName() {
return userName;
}
public int getUserType() {
return userType;
}
}
public class Main {
public static void main(String[] args) {
User u = new User();
System.out.println(u.getUserName());
System.out.println(u.getUserType());
}
}
Which of the following is the output?
(a)   null null
(b)   null   0
(c)   error
(d)   0   null
(e) 0    0
169.
Consider the following segment of a Java program:
int x=1;
switch(x)
{
case 0:System.out.println(x);break;
case 1:System.out.println(x);break;
case 2:System.out.println(x);
default: System.out.println(x);
}
What will the output be when the above segment is executed as a program?
(a) 0
(b) 1
(c) 2
(d)   1   1
(e) error
170.
Consider the following program written in Java:
class Iteration{
public static void main(String args[])
{
for(int i=0;i<5;i++)
{
System.out.println(i);
if(i%2==0)
System.out.println('\t');
}
}
}
When the program is executed what would the outcome be?
(a)   0
1
2
3
4
5
(b)   0
1
2
3

(c)   01 23 4
(d)   0
1
2
3
4
5
(e)   0
1
2
3
4




Answers



161.
Answer : (e)
Reason : Remaining all are mark up languages
162.
Answer : (c)
Reason : the remaining all would not give the required output
163.
Answer : (a)
Reason : After execution the output of the given question is of choice A other are contradictory
164.
Answer : (c)
Reason : When one oper and is floating value and the other operated is string, the ‘+’ operator acts like concantenation. So the result would be a string of 75.225.2”.
165.
Answer : (e)
Reason : Not a valid code
166.
Answer : (c)
Reason : The extracted string of 10, 13 is OF
167.
Answer : (e)
Reason : True because equalsignorecase ignores case and returns true
168.
Answer : (b)
Reason : Remaining all are contradictory.
169.
Answer : (b)
Reason : x is taken as 1 and case 1 is executed and comes out of the switch.
170.
Answer : (e)
Reason : In other cases the values are less compared to required output.



<< 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 >>


2 comments :