New Text Document
New Text Document
html
saved from :
http://www.geocities.com/siliconvalley/orchard/9362/java/javacert/poddar.html
ans:
a) false
false
false
dar
b) false
true
false
poddar
c) compiler error
d) true
true
false
dar
correct answer is a)
***** look carefully at code and answer the following questions ( q2 to q8)
1 import java.applet.applet;
2 import java.awt.*;
3 import java.awt.event.*;
4 public class hello4 extends applet {
5 public void init(){
6 add(new mybutton("bbb"));
7 }
8 public void paint(graphics screen) {
9 }
10 class mybutton extends button{
11 mybutton(string label){
12 super(label);
13 }
14 public string paramstring(){
15 return super.paramstring();
16 }
17 }
18 public static void main(string[] args){
19 frame myframe = new frame(
20 "copyright amit");
21 myframe.setsize(300,100);
22 applet myapplet = new hello4();
23 button b = new button("my button");
24 myapplet.add(b);
25 b.setlabel(b.getlabel()+"new");
26 // mybutton b1 =(new hello4()).new mybutton("parambutton");
27 system.out.println(b1.paramstring());
28 myframe.add(myapplet);
29 myframe.setvisible(true);
30 myframe.addwindowlistener(new windowadapter(){
31 public void windowclosing(windowevent e){
32 system.exit(0);}});
33 }
34 } //end hello4 class.
q2. if you run the above program via appletviewer ( defining a html file), you see
on screen.
a) two buttons
b) one button with label as "bbb"
c) one button with label as "my buttonnew"
d) one button with label as "my button"
correct answer is b)
q3. in the above code if line 26 is uncommented and program runs as standalone
application
a) compile error
b) run time error
c) it will print the the label as parambutton for button b1
correct answer is c)
correct answer is b)
q5. if above program is run as a standalone application. how many buttons will be
displayed
a) two buttons
b) one button with label as "bbb"
c) one button with label as "my buttonnew"
d) one button with label as "my button"
correct answer is c)
q6. if from line no 14 keyword "public" is removed, what will happen.( hint
:paramstring() method in java.awt.button is a protected method. (assume line 26
is uncommented)
correct answer is a). as you can not override a method with weaker access
privileges
q7. if from line no 14 keyword "public" is replaced with "protected", what will
happen.(hint :paramstring() method in java.awt.button is a protected
method.(assume line 26 is uncommented)
a) code will not compile.
b) code will compile but will give a run time error.
c) code will compile and no run time error.
correct answer is c) . as you can access a protected variable in the same package.
correct answer is a) because protected variables and methods can not be accssed in
another package directly. they can only be accessed if the class is subclassed and
instance of subclass is used.
q9. what is the output of following if the return value is "the value 0 if the
argument string is equal to this string; a value less than 0 if this string is
lexicographically less than the string argument; and a value greater than 0 if
this string is lexicographically greater than the string argument" (assuming
written inside main)
string s5 = "amit";
string s6 = "amit";
system.out.println(s5.compareto(s6));
system.out.println(s6.compareto(s5));
system.out.println(s6.compareto(s6));
ans
a> -32
32
0
b> 32
32
0
c> 32
-32
0
d> 0
0
0
correct answer is a)
a) compile error
b) amitpoddar
o
c) amitpoddar
i
d) amit
i
a) arit
amit
false
true
b) arit
arit
false
true
c) amit
amit
false
true
d) arit
amit
true
true
correct answer is a) s3==s4 is true because java points both s3 and s4 to same
memory location in string pool
q15. which checkbox will be selected in the following code ( assume with main and
added to a frame)
frame myframe = new frame("test");
checkboxgroup cbg = new checkboxgroup();
checkbox cb1 = new checkbox("first",true,cbg);
checkbox cb2 = new checkbox("scond",true,cbg);
checkbox cb3 = new checkbox("third",false,cbg);
cbg.setselectedcheckbox(cb3);
myframe.add(cb1);
myframe.add(cb2);
myframe.add(cb3);
a) cb1
b) cb2,cb1
c) cb1,cb2,cb3
d) cb3
q16) which checkbox will be selected in the following code ( assume with main and
added to a frame)
frame myframe = new frame("test");
checkboxgroup cbg = new checkboxgroup();
checkbox cb1 = new checkbox("first",true,cbg);
checkbox cb2 = new checkbox("scond",true,cbg);
checkbox cb3 = new checkbox("third",true,cbg);
myframe.add(cb1);
myframe.add(cb2);
myframe.add(cb3);
a) cb1
b) cb2,cb1
c) cb1,cb2,cb3
d) cb3
correct answer is c)
correct answer is b)
correct answer is d)
a) checkbox
b) canvas
c) checkbocgroup
d) label
correct answer is c)
correct answer is a)
q22) for awt components which of the following statements are true?
a) if a component is not explicitly assigned a font, it usese the same font that
it container uses.
b) if a component is not explicitly assigned a foreground color , it usese the
same foreground color that it container uses.
c) if a component is not explicitly assigned a backround color , it usese the same
background color that it container uses.
d) if a component is not explicitly assigned a layout manager , it usese the same
layout manager that it container uses.
correct answer is b)
answers:
a) ceil for d1 0
floor for d1 -1;
b) ceil for d1 0
floor for d1 -1.0;
c) ceil for d1 0.0
floor for d1 -1.0;
d) ceil for d1 -0.0
floor for d1 -1.0;
b)round f4 is -5
round f5 is 6
round f6 is -5
round f7 is 5
correct answer is b)
{
float f4 = integer.min_value;
float f5 = integer.max_value;
float f7 = -2147483655f;
system.out.println("round f4 is " + math.round(f4));
system.out.println("round f5 is " + math.round(f5));
system.out.println("round f7 is " + math.round(f7));
}
a)round f4 is -2147483648
round f5 is 2147483647
round f7 is -2147483648
b)round f4 is -2147483648
round f5 is 2147483647
round f7 is -2147483655
correct answer is a)
//reason if the argument is negative infinity or any value less than or equal to
the value of integer.min_value, the result is
equal to the value of integer.min_value.
if the argument is positive infinity or any value greater than or equal to the
value of integer.max_value, the result is
equal to the value of integer.max_value. // from jdk api documentation
q27)
1 boolean b1 = new boolean("true");
2 boolean b2 = new boolean("true");
3 boolean b3 = new boolean("junk");
4 system.out.println("" + b1 + b2 + b3);
a) comiler error
b) runtime error
c)truetruefalse
d)truetruetrue
correct answer is c)
a) runtime error
b) infinity
-infinity
4.4e99
c) infinity
-infinity
infinity
d) 4.4e99
-4.4e99
4.4e99
correct answer is b)
1) boolean
2) integer
3) long
4) character
5) byte
6) short
correct answer is 4)
a) true
true
b) false
false
c) true
false
d) false
true
correct answer is d)
q32) which one of the following always honors the components's preferred size.
a) flowlayout
b) gridlayout
c) borderlayout
correct answer is a)
correct answer is b) reason- frame uses border layout which places the button to
centre
(by default) and ignores button's preferred size.
q34 if the code in q33 is compiled and run via appletviewer what will happen
a) displays an empty applet
b) displays a applet with a button covering the entire frame
c) displays a applet with a button large enough to accomodate its label.
a) x is 300
y is 300
b) x is 0
y is 0
c) x is 0
y is 300
correct answer is b)
import java.io.*;
public class io {
public static void main(string args[]) {
file f = new file("..\\12345.msg");
try{
system.out.println(f.getcanonicalpath());
system.out.println(f.getabsolutepath());
}catch(ioexception e){
system.out.println(e);
}
}
}
b) c:\java\dir1\12345.msg
c:\java\dir1\..\12345.msg
c) c:\java\dir1\..\12345.msg
c:\java\dir1\..\12345.msg
b) c:\12345.msg
c:\java\..\12345.msg
c) c:\java\..\12345.msg
c:\java\\..\12345.msg
correct answer is b)
q39) which one of the following methods of java.io.file throws ioexception and why
correct answer is b)
import java.io.*;
public class io {
public static void main(string args[]) {
file f = new file("12345.msg");
string arr[] = f.list();
system.out.println(arr.length);
}
}
correct ansewer is b)
import java.io.*;
public class io {
public static void main(string args[]) {
file f1 = new file("\\12345.msg");
system.out.println(f1.getpath());
system.out.println(f1.getparent());
system.out.println(f1.isabsolute());
system.out.println(f1.getname());
system.out.println(f1.exists());
system.out.println(f1.isfile());
}
}
a) \12345.msg
\
true
12345.msg
true
true
b) \12345.msg
\
true
\12345.msg
false
false
c) 12345.msg
\
true
12345.msg
false
false
d) \12345.msg
\
true
12345.msg
false
false
correct answer is d)
a) 12345.msg
\
true
12345.msg
true
true
b) 12345.msg
null
true
12345.msg
true
true
c) 12345.msg
null
false
12345.msg
true
true
d) \12345.msg
\
true
12345.msg
false
false
correct answer is c)