radhika ayirala

Greenhorn
+ Follow
since Aug 28, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by radhika ayirala

can we apply autoboxing concept here.If we apply that,we can change Integer to int.Then line4 would be valied.
16 years ago
Which line(s) should be removed for this code to compile?
static public void main(String...arg)
{
Byte snake = 5;
final int b;
b=2;
Integer i=5;
switch(snake){
case 128:System.out.println("Shouldn't it freeze in December ?");//1
default:System.out.println("White Christmas?");//2
case b:System.out.println("An Inconvenient truth...");//3
case i:break;//4
}
}

why line4 is wrong.
16 years ago
What is put on screen?
static public void main(String...arg)
{
int i=1;
int result = 5+i++%4*i;
System.out.println(result);
}

please explain how the output is 7.
16 years ago
// Line 1:
list < ? super String> list = new ArrayList <String>> ();


// Line 2:
list.add(new Object());

Drag and Drop the following options over Line 1 and Line 2. Drag the relevant fragment over the line to indicate whether or not the Line will not compile, or if will compile, whether it will throw Exceptions.

The answers are :
Line1: compiles fine with no runtime exceptions.
Line2:compiletime error.

please explain.
Here is the answer:

FALSE : This code fragment will not compile
TRUE : Nothing can be added to this List.
TRUE : Anything beside Integer could be replaced on the right hand side.
Drag and drop either "true" or "false" above the following options that are based on this code fragment.
List < ? > l = new ArrayList< Integer > ();

: This code fragment will not compile
: Nothing can be added to this List.
: Anything beside Integer could be replaced on the right hand side.

I coudn't understand the question.Can you please explain.What is ? >.
I am sorry,let me reformat the question.

PROGRAM1:
class test1
{
public static void main(String args[])
{
int []arr = {1,2,3,4};
for ( int i : arr )
{
arr[i] = 0;
System.out.println(arr[i]);
}

for ( int i : arr )
{
System.out.println(i);
}
}
}

PROGRAM2:
class test2
{
public static void main(String args[])
{
int []arr = {1,2,3,4};
System.out.println("arr.length"+arr.length);
for ( int i =0;i<arr.length;i++ )
{
arr[i] = 0;
System.out.println("one"+arr[i]);
}

for ( int i : arr )
{
System.out.println("two"+i);
}
}
}

Why the ouput of program1 is not "0000".please explain.
FIRST PROGRAM:
class test1
{
public static void main(String args[])
{
int []arr = {1,2,3,4};
for ( int i : arr ) -------------------------->1
{
arr[i] = 0;
System.out.println(i);
}

for ( int i : arr )
{
System.out.println(i);
}
}
}

SECONDPROGRAM:

class test2
{
public static void main(String args[])
{
int []arr = {1,2,3,4};
for ( int i =0;i<arr.length;i++ )------------------>2
{
arr[i] = 0;
System.out.println("one"+i);
}

for ( int i : arr )
{
System.out.println("two"+i);
}
}
}


My doubts are.
1. Are the 2 for loops : for ( int i =0;i<arr.length;i++ )
for ( int i : arr )
same?
2.If they are same,how come output is different.

3.Why the output of program1's 2nd for loop is not "0000"?
please explain.
public class test
{
public static void main( String [] args )
{
new test();
}
test()
{
test(2);
}
test(int x)
{
System.out.println(x);
}
}


why is this giving an error?
I got it.Thanks.Can you please tell me,why elements are not comparable.
import java.util.*;
class test implements Comparator<test>
{
private int x;
test(int input) { x = input; }
public static void main( String args[] )
{
List list = new ArrayList();
list.add(new test(2));
list.add(new test(2));
Collections.sort(list);
}
public int compare( test t1 , test t2 )
{
return t1.x - t2.x;
}
}
The explanation for the above program.

This code will throw a ClassCastException. This version of Collections.sort() banks on the Comparable interface being implemented, not the Comparator interface. No comparator is passed to the sort() method.

I couldn't understand the above explanation.Please explain.
Thanks for the suggestions.I will try to postpone the exam.
Hi,

My exam(310-055) is on 09/21/2007.I followed kathysierra book.I am not getting good score in mock exams.I just want to pass the exam.Can any one give me some suggestions.Like which topics i should be strong,some links to mock exam.I dont want to fail.I just want to pass the exam.

Thanks,
-Radhika