Java Programming Questions and Answers Set 18

Java Programming OOPs

Questions 171 to 180



171.
Consider the following Java applet program:
import java.awt.*;
import java.applet.*;
public class Applet1 extends applet {
int i = 1, j = 2, k = 3, l = 4;
boolean b = false;
public void init() {
i = j + 1;
b = true;
k = l - 2;
}
public void start() {
j = i + 2;
}
public void stop() {
j = k + 1;
}
public void destroy() {
l = i + 5;
}
}
Which of the following is the value of the variable i soon after the statement b = true and after pressing the restart option in the applet viewer?
(a) 1                        (b) 2                        (c) 3                        (d) 4                        (e) 5.
172.
Consider the following program written in Java:
class For{
public static void main(String args[])
{
for(int i=0; i<=2; System.out.println(i););
}
}
What would the output of the above program be when the program is executed?
(a)   0
1
2
(b)   2
1
0
(c)   error
(d)   1
2
(e)   2
1
173.
Consider the following Java program:
class While{
public static void main(String args[]){
int x=0;
while(x=<3) {
System.out.println(x);
if(x==2)
continue;
x++;
}
}
}
What would be the output of the above program if executed?
(a)   0
1
2
3
(b)   0
1
3
(c)   1
2
3
(d)   error
(e)   2
174.
Consider the following program written in Java:
class Args{
public static void main(String args[]) {
System.out.println(args[0]);
System.out.println(args[1]);
}
}
The above program is supplemented with the following command line assuming that the program has been compiled without any errors.
java Args args zero one
What would the output be?
(a)   Args
args
(b)   Args args
(c)   args
zero
(d)   args zero
(e)   zero one
175.
Consider the following program written in Java:
class DoWhile{
public static void main(String args[])
{
int j=0;
do{
int k=7;
System.out.println(k);
k+=7;
j++;
}
while(j<3);
}
}
What would be the output of the program if it is executed?
(a)   7
8
9
(b)   7
7
7
(c)   7
14
21
(d)   7
15
22
(e)   error
176.
Consider the following Java program:
class Arr1{
public static void main(String args[]) {
String[] Names={Sarma,Devi,Rakesh};
Names[2]=Ravi;
for(int i=0;i<Names.length;i++)
System.out.println(Names[i]);
}
}
What would the output of the above program be if executed?
(a)   Sarma   
Devi
Rakesh
(b)   Sarma
Devi
Rakesh Ravi
(c)   Sarma
Devi Ravi
Rakesh
(d)   error
(e)   Sarma
Devi
Ravi
177.
Consider the following program written in Java:
class Arr{
public static void main(String args[]){
int arr[]=new int[5];
for(int i=1;i<arr.length;i++)
arr[i]=i;
for(int j=0;j<arr.length;j++)
System.out.println(arr[j]);
}
}
What would the output of the program be if it is executed?
(a)   0
1
2
3
4
(b)   error
(c)   null
0
1
2
3
(d)   0
0
1
2
3
(e)   0
0
1
1
2
178.
Consider the following program written in Java:
import java.awt.*;
import java.applet.Applet;
public class AwtEx extends Applet{
Checkbox ch1=new Checkbox("Advance Certificate");
Checkbox ch2=new Checkbox("Degree Certificate");
public void init(){ add(ch1); add(ch2);
}
}
After compiling the program, the following set of codes is also written and saved separately by giving the name Awt.html.
<applet code="AwtEx.class" height=100 width=150> </applet>
What would be the outcome when appletviewer is invoked by providing the file Awt.html?
(a)  
(b)
(c)
      
(d)  
(e)

179.
JAR File stands for
(a)   Java  Runtime File                           (b)  Java Archive File
(c)   Java Applet File                                                            (d)  Java Remote Method File
(e)   Java applet Restart File.
180.
Pick up the correct order of the life cycle of servlet :
i.     Look up any HTTP information
           Determine the browser version, host name of client, cookies, etc.
ii.     Read any data sent by the user
           Capture data submitted by an HTML form.
iii.    Format the Results
           Generate HTML on the fly
iv.    Set the Appropriate HTTP headers
           Tell the browser the type of document being returned or set any cookies.
v.    Generate the Results
           Connect to databases, connect to legacy applications, etc.
vi.    Send the document back to the client
(a)   ii,i,v,iii,iv,vi        (b)  i,ii,iv,iii,v,vi        (c)  i,ii,iii,v,vi,iv        (d)  ii,v,i,iv,vi,iii (e)  ii,v,i,iii,iv,vi.


Answers


171.
Answer : (d)
Reason : All other cases are not valid results.
172.
Answer : (c)
Reason : Declaration itself is incorrect.
173.
Answer : (d)
Reason : while condition syntax is incorrect.
174.
Answer : (c)
Reason : the output is args zero remaining all are contradictory to code
175.
Answer : (b)
Reason : very time k is initialized to 7 overwriting incremented values. Remaining all are incorrect.
176.
Answer : (d)
Reason : remaining all are incorrect.
177.
Answer : (a)
Reason : Choice A is the correct layout of the code.
178.
Answer : (a)
Reason : Choice A is the correct layout of the code.
179.
Answer : (b)
Reason : Remaining all JAR stands for Java Achieve, where as others specially different concepts of Java.
180.
Answer : (a)
Reason : The order of life cycle of servlet is choice a and the remaining all are incorrect



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


No comments :

What you think about these Questions and Answers ? Let me know in comments.

Post a Comment