Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
5Activity
0 of .
Results for:
No results containing your search query
P. 1
Main Exam 9

Main Exam 9

Ratings: (0)|Views: 219 |Likes:
Published by api-3730216

More info:

Published by: api-3730216 on Oct 18, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Question 1 of 61
Which code fragments will print the last argument given on the command line to the
standard output, and exit without any output and exceptions if no arguments are given?
1.public static void main(String args[ ])
{
if (args.length != 0)
System.out.println(args[args.length-1]);
}

2.
public static void main(String args[ ])
{

try {
System.out.println(args[args.length-1]);
}
catch (ArrayIndexOutOfBoundsException e) {
}
}3.public static void main(String args[ ])

{
int i = args.length;
if (i != 0) System.out.println(args[i-1]);

}4.
public static void main(String args[ ])
{
int i = args.length-1;
if (i > 0) System.out.println(args[i]);
}5.public static void main(String args[ ])

{
try { System.out.println(args[args.length-1]); }
catch (NullPointerException e) {}

}
Select 3 correct options
a
Code No. 1
b
Code No. 2
c
Code No. 3
d
Code No. 4
e
Code No. 5
Question 2 of 61
What will be the result of attempting to compile and run class B?
class A
{
final int fi = 10;
}class B extends A

{
int fi = 15;
public static void main(String[] args)
{

B b = new B();
b.fi = 20;
System.out.println(b.fi);

System.out.println( ( (A) b ).fi );
}
}
Select 1 correct option.
a
It will not compile.
b
It will print 10 and then 10
c
It will print 20 and then 20
d
It will print 10 and then 20
e
It will print 20 and then 10
Question 3 of 61
What will the following program print?
class LoopTest

{
public static void main(String args[])
{

int counter = 0;
outer: for(int i = 0; i < 3; i++)
middle: for(int j = 0; j < 3; j++)
inner: for(int k = 0; k < 3; k++)

{
if(k-j>0) break middle;
counter++;

}
System.out.println(counter);
}
}
Select 1 correct option.
a
2
b
3
c
6
d
7
e
9
Question 4 of 61
Given the following program, which statment is true?
class SomeClass

{
public static void main( String args[ ] )
{

if (args.length == 0 )
{
System.out.println("no arguments") ;
}else
{
System.out.println( args.length + " arguments.") ;
}
}
}
Select 1 correct option.
a
The program will fail to compile.
b
The program will throw a NullPointerException when run with zero arguments.
c
The program will print "no arguments" and "1 arguments" when called with
zero and one arguments.
d
The program will print "no arguments" and "2 arguments" when called with
zero and one arguments.
e
The program will print "no arguments" and "3 arguments" when called with
zero and one arguments.

Activity (5)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Narendra Reddy liked this
hick2222 liked this
ganesh_karanam liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->