[go: up one dir, main page]

0% found this document useful (0 votes)
60 views9 pages

Ex Amen Java

1) The code will compile and run without errors. It creates an object of class Base and calls the protected method amethod() from the subclass Class1, printing "amethod". 2) If Base.java has not been previously compiled, compiling and running Class1 will result in a compile error stating that the superclass of Class1, Base, cannot be found. 3) The code provided contains the Base and Class1 classes in the same package, with Class1 extending Base and calling the protected method defined in Base.

Uploaded by

Marcela Pascua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views9 pages

Ex Amen Java

1) The code will compile and run without errors. It creates an object of class Base and calls the protected method amethod() from the subclass Class1, printing "amethod". 2) If Base.java has not been previously compiled, compiling and running Class1 will result in a compile error stating that the superclass of Class1, Base, cannot be found. 3) The code provided contains the Base and Class1 classes in the same package, with Class1 extending Base and calling the protected method defined in Base.

Uploaded by

Marcela Pascua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Examen para el puesto de Ingeniero de Desarrollo de Sistemas (Java)

Nombre:___________________________________________________
Fecha:_____________________________________________________
uestion !)
"hich o# the #ollo$ing lines $ill compile $ithout $arning or error%
1) float f=1.3;
2) char c="a";
3) byte b=257;
4) boolean b=null;
5) int i=10;
uestion &)
A byte can be of what size
1) 12! to 127
2) "2 #ower ! )1 to 2 #ower !
3) 255 to 25$
4)%e#en%s on the #articular i&#le&entation of the 'a(a )irtual &achine
uestion ')
*hich of the followin+ are le+al i%entifiers
1) 2(ariable
2) (ariable2
3) ,whata(ariable
4) ,3,
5) -another(ar
$) .&y(ar
uestion ()
*hat will ha##en if you try to co&#ile an% run the followin+ co%e/
public class Q {
public static void main(String argv[]){
int anar[]=new int[5];
System.out.println(anar[]);
!
!
1) 0rror1 anar is reference% before it is initialize%
2) null
3) 0
4) 5
uestion ))
*hat will be #rinte% out if you atte&#t to co&#ile an% run the followin+
co%e/
int i=";
switc# (i) {
de$ault%
System.out.println(&de$ault&);
case %
System.out.println(&'ero&);
brea(;
case )%
System.out.println(&one&);
case *%
System.out.println(&two&);
!
1) %efault
2) %efault2 zero
3) error %efault clause not %efine%
4) no out#ut %is#laye%
uestion *)
*hich of the followin+ state&ents are true/
1) 3etho%s cannot be o(erri%en to be &ore #ri(ate
2) static &etho%s cannot be o(erloa%e%
3) #ri(ate &etho%s cannot be o(erloa%e%
4) An o(erloa%e% &etho% cannot throw e4ce#tions not chec5e% in the base
class
uestion +)
*hat will ha##en when you atte&#t to co&#ile an% run the followin+ co%e/
public class +u, e,tends +#read{
static String s-ame = &vandeleur&;
public static void main(String argv[]){
+u, t = new +u,();
t.piggy(s-ame);
System.out.println(s-ame);

!
public void piggy(String s-ame){
s-ame = s-ame . & wiggy&;
start();
!
public void run(){

$or(int i=;i / 0; i..){
s-ame = s-ame . & & . i;

!
!
!
1) 6o&#ile ti&e error
2) 6o&#ilation an% out#ut of "(an%eleur wi++y"
3) 6o&#ilation an% out#ut of "(an%eleur wi++y 0 1 2 3"
4) 6o&#ilation an% out#ut of either "(an%eleur"2 "(an%eleur 0"2 "(an%eleur 0
1" "(an%aleur 0 1 2" or "(an%aleur 0 1 2 3"
uestion ,)
*hat will ha##en if you atte&#t to co&#ile an% run the followin+ co%e/
1nteger ten=new 1nteger());
2ong nine=new 2ong (");
System.out.println(ten . nine);
int i=);
System.out.println(i . ten);
1) 17 followe% by 20
2) 17 followe% by 11
3) 6o&#ile ti&e error
4) 10 followe% by 1
uestion -)
*hich state&ent is true of the followin+ co%e/
public class 3gg{
public static void main(String argv[]){
3gg a = new 3gg();
a.go();
!
public void go(){
4S5oss ds) = new 4S5oss(&one&);
ds).start();
!
!
class 4S5oss e,tends +#read{
private String s+name=&&;
4S5oss(String s){
s+name = s;
!
public void run(){
notwait();
System.out.println(&$inis#ed&);
!
public void notwait(){
w#ile(true){
try{
System.out.println(&waiting&);
wait();
!catc#(1nterrupted6,ception ie){!
System.out.println(s+name);
noti$y3ll();
!
!
!
1) 8t will cause a co&#ile ti&e error
2) 6o&#ilation an% out#ut of "waitin+"
3) 6o&#ilation an% out#ut of "waitin+" followe% by "finishe%"
4) 9unti&e error2 an e4ce#tion will be thrown
uestion !.)
:i(en the followin+ %eclarations
String s)=new String(&7ello&)
String s*=new String(&t#ere&);
String s8=new String();
*hich of the followin+ are le+al o#erations/
1) s3=s1 ; s2;
2) s3=s1s2;
3) s3=s1 < s2;
4) s3=s1 << s2
uestion !!)
*hat will ha##en when you atte&#t to co&#ile an% run the followin+ co%e/
public class 7olt e,tends +#read{
private String s+#read-ame;
public static void main(String argv[]){
7olt # = new 7olt();
#.go();
!
7olt(){!
7olt(String s){
s+#read-ame = s;
!
public String get+#read-ame(){
return s+#read-ame;
!
public void go(){
7olt $irst = new 7olt(&$irst&);
$irst.start();
7olt second = new 7olt(&second&);
second.start();
!
public void start(){
$or(int i = ; i / *; i ..){
System.out.println(get+#read-ame() .i);
try{
+#read.sleep());
! catc#(1nterrupted6,ception e)
{System.out.println(e.get9essage());!
!
!
!
1) 6o&#ile ti&e error
2) =ut#ut of first02 secon%02 first02 secon%1
3) =ut#ut of first02 first12 secon%02 secon%1
4) 9unti&e error
uestion !&)
*hich of the followin+ state&ents about this co%e are true/
public class 9orecombe{
public static void main(String argv[]){
9orecombe m = new 9orecombe();
m.go(new +uring(){!);
!
public void go(+uring t){
t.start();
!
!
class +uring e,tends +#read{
public void run(){
$or(int i =; i / *; i..){
System.out.println(i);
!
!
!
1) 6o&#ilation error %ue to &alfor&e% #ara&eter to +o &etho%
2) 6o&#ilation error2 class >urin+ has no start &etho%
3) 6o&#ilation an% out#ut of 0 followe% by 1
4) 6o&#ilation but runti&e error
uestion !')
:i(en the followin+ co%e
import :ava.awt.;;
public class Set< e,tends <rame{
public static void main(String argv[]){
Set< s=new Set<();
s.setSi'e(8=*);
s.set>isible(true);
!
!
?ow coul% you set the fra&e surface color to #in5
1)s.set@ac5+roun%"6olor.#in5);
2)s.set6olor"A8BC);
3)s.@ac5+roun%"#in5);
4)s.color=6olor.#in5
uestion !()
:i(en the followin+ co%e how coul% you in(o5e the @ase constructor that will
#rint out the strin+ "base constructor";
class ?ase{
?ase(int i){
System.out.println(&base constructor&);
!
?ase(){
!
!
public class Sup e,tends ?ase{
public static void main(String argv[]){
Sup s= new Sup();
@@Ane
!
Sup()
{
@@+wo
!
public void derived()
{
@@+#ree
!
!
1) =n the line After DD=ne #ut @ase"10);
2) =n the line After DD=ne #ut su#er"10);
3) =n the line After DD>wo #ut su#er"10);
4) =n the line After DD>hree #ut su#er"10);
uestion !))
*hat will be the result when you try to co&#ile an% run the followin+ co%e/
private class ?ase{
?ase(){
int i = );
System.out.println(i);
!
!
public class Bri e,tends ?ase{
static int i = *;
public static void main(String argv[]){
Bri p = new Bri();
System.out.println(i);
!
!
1) 0rror at co&#ile ti&e
2) 200
3) 100 followe% by 200
4) 100
uestion !*)
Eou nee% to create a class that will store uniFue obGect ele&ents. Eou %o not
nee% to sort these ele&ents but they &ust be uniFue.
*hat interface &i+ht be &ost suitable to &eet this nee%/
1)Het
2)Iist
3)3a#
4))ector

uestion !+)
*hat will be the result when you atte&#t to co&#ile this #ro+ra&/
public class 5and{
public static void main(String argv[]){
int i5and;
i5and = 9at#.random();
System.out.println(i5and);
!
!
1) 6o&#ile ti&e error referrin+ to a cast #roble&
2) A ran%o& nu&ber between 1 an% 10
3) A ran%o& nu&ber between 0 an% 1
4) A co&#ile ti&e error about ran%o& bein+ an unreco+nise% &etho%
uestion !,)
Eou want to lay out a set of buttons horizontally but with &ore s#ace between
the first button an% the rest. Eou are +oin+ to use the :ri%@a+Iayout &ana+er to
control the way the buttons are set out. ?ow will you &o%ify the way the
:ri%@a+Iayout acts in or%er to chan+e the s#acin+ aroun% the first button/

1) 6reate an instance of the :ri%@a+6onstraints class2 call the wei+ht4")
&etho% an% then #ass the :ri%@a+6onstraints instance with the co&#onent to
the set6onstraints &etho% of the :ri%@a+Iayout class.
2) 6reate an instance of the :ri%@a+6onstraints class2 set the wei+ht4 fiel%
an% then #ass the :ri%@a+6onstraints instance with the co&#onent to the
set6onstraints &etho% of the :ri%@a+Iayout class.
3) 6reate an instance of the :ri%@a+Iayout class2 set the wei+ht4 fiel% an%
then call the set6onstraints &etho% of the :ri%@a+Iayout6lass with the
co&#onent as a #ara&eter.
4) 6reate an instance of the :ri%@a+Iayout class2 call the set*ei+ht4")
&etho% an% then #ass the :ri%@a+6onstraints instance with the co&#onent to
the set6onstraints &etho% of the :ri%@a+Iayout class.
uestion !-)
Eou are concerne% that your #ro+ra& &ay atte&#t to use &ore &e&ory than
is a(ailable. >o a(oi% this situation you want to ensure that the 'a(a )irtual
3achine will run its +arba+e collection Gust before you start a co&#le4
routine. *hat can you %o to be certain that +arba+e collection will run when
you want .
1) Eou cannot be certain when +arba+e collection will run
2) Jse the 9unti&e.+c") &etho% to force +arba+e collection
3) 0nsure that all the (ariables you reFuire to be +arba+e collecte% are set to
null
4) Jse the Hyste&.+c") &etho% to force +arba+e collection
uestion &.)
Eou ha(e these files in the sa&e %irectory. *hat will ha##en when you
atte&#t to co&#ile an% run 6lass1.Ga(a if you ha(e not alrea%y co&#ile%
@ase.Ga(a
@@?ase.:ava
pac(age ?ase;
class ?ase{
protected void amet#od(){
System.out.println(&amet#od&);
!@@6nd o$ amet#od
!@@6nd o$ class base
pac(age Class);
@@Class).:ava
public class Class) e,tends ?ase{
public static void main(String argv[]){
?ase b = new ?ase();
b.amet#od();
!@@6nd o$ main
!@@6nd o$ Class)
1) 6o&#ile 0rror1 3etho%s in @ase not foun%
2) 6o&#ile 0rror1 Jnable to access #rotecte% &etho% in base class
3) 6o&#ilation followe% by the out#ut "a&etho%"
4)6o&#ile error1 Hu#erclass 6lass1.@ase of class 6lass1.6lass1 not foun%

You might also like