Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

Preetha Vasudevan

Ranch Hand
+ Follow
since Sep 23, 2005
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 Preetha Vasudevan

Hi jeff
I tried compiling the code and it gives me a compiler error saying incompatible type at line 3 of the code.My doublt is in line 2 .can we assign a subclass reference to the Basket class using generics.
18 years ago
Hi all
I have a major doubt about generics related to the following code shown below.This code is a question from javabeat.net generics mock exam.
code:
class Basket<E> {
private E element;

public void setElement(E x) {
element = x;
}

public E getElement() {
return element;
}
}

class Fruit {
}

class Apple extends Fruit {
}

class Orange extends Fruit {
}
class GeneTest{
public static void main(String args[]){

Basket<Fruit> basket = new Basket<Fruit>(); // 1
basket.setElement(new Apple()); // 2
Apple apple = basket.getElement(); // 3
}
The answer to the question is that The line 3 however will cause a runtime error. The result type of the methode getElement of Basket<Fruit> is Fruit. We cannot assign a Fruit to a variable of the type Apple without a cast.
According to me the answer to this code would be that it generates a compiler error at line 2.Because i thought that Basket class is parametarized to contain only Fruits.even though Apple class is a subclass of the Fruit class i thought as generics go against subtyping it would cause an compiler error.
can anyone explain this concept in a better way..

Thank you..
18 years ago
Hi all
I have a major doubt about generics related to the following code shown below.This code is a question from javabeat.net generics mock exam.
code:
class Basket<E> {
private E element;

public void setElement(E x) {
element = x;
}

public E getElement() {
return element;
}
}

class Fruit {
}

class Apple extends Fruit {
}

class Orange extends Fruit {
}
class GeneTest{
public static void main(String args[]){

Basket<Fruit> basket = new Basket<Fruit>(); // 1
basket.setElement(new Apple()); // 2
Apple apple = basket.getElement(); // 3
}
The answer to the question is that The line 3 however will cause a runtime error. The result type of the methode getElement of Basket<Fruit> is Fruit. We cannot assign a Fruit to a variable of the type Apple without a cast.
According to me the answer to this code would be that it generates a compiler error at line 2.Because i thought that Basket class is parametarized to contain only Fruits.even though Apple class is a subclass of the Fruit class i thought as generics go against subtyping it would cause an compiler error.
can anyone explain this concept in a better way..

Thank you..
hi
I got the output :ABAB
hi all
I found this question i one of the mock exams and was not able to get the output ..

code:
class Test implements Runnable {
public void run() {
String str = new String("Hello");
synchronized(str){
try
{
System.out.println(Thread.currentThread().getName());
Thread.sleep(5000);
System.out.println(Thread.currentThread().getName());
}
catch(InterruptedException e){}
}
}
}
public static void main(String args[])
{
new Thread(new Test(),"A").start();
new Thread(new Test(),"B").start();
}
}
Thanks in advance.
I think it should give you a compiler error because you shuld enclose
the sleep() in a try catch block or atleast declare it even if you are not handling it
Hi all
Isolating reference which is one of the way that an object becomes eligible for garbage collection can anyone explain me the exact meaning of this method with an example.

Thanks in advance..
Hi all
Isolating reference which is one of the way that an object becomes eligible for garbage collection can anyone explain me the exact meaning of this method with an example.

Thanks in advance..
18 years ago
Hi all
I have java 5.0 Tiger book which lists all the format specifiers for date and time formatting.Do we have know all of them because its very confusing to rememeber .And would also like to know if the whizlabs simulator for SJCP 5.0 is good to pass the exam..

Thanks in advance!!
Hi all
I am from singapore and i am intrested to take scjp 5.0 ..can anyone tell me from where i can buy the voucher from..

Thanks in advance
I found this question in one of the mock exams on assertions is says that the methodA int the class Asserttest throws Assertion error which of the following method can be legally placed in the subclass of the Asserttest

code:
public class Asserttest{
public void methodA(int i) throws AssertionError
{
assert i<1024:"Invalid value";
}
}

The options are:
1. public void methodA(int i)
2. public void methodA(int i) throws Exception
3. public void methodA(int i) throws Throwable
4. public void methodA(int i) throws Error
5. only A is the valid option

i answered as 1,5 but the answer is 1,4 how is option 4 right please explain...
hi all
I would like to know if metadata is included for scjp 5.0
Thanks jairam for your prompt reply but i might sound stupid ..
how 15 objects will be eligible for garbage collection after the end of the main method??
Hi all
I found this question related to garbage collection.can anyone tell what the output of this code would be

public static void main(String args[])
{
Double x= new Double(0);
for(int i=0;i<5;i++)
for(int j=0;j<3;j++)
x = new Double(i+j)
int a = x.intvalue();
System.out.println("a = +" a);
}