Vidhya Hari

Greenhorn
+ Follow
since Mar 20, 2006
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 Vidhya Hari

Im very glad to share with u tht i cleared SCJp1.4 with a 90% mark...I'd like to encourage everyone trying for a decent score on scjp to work on the danchisholm questions from the day u decide to take the exam..very helpful..marcus green has an awesome compilation of to-the-point questions.
East or West,javaranch is the best for all aspiring java folks..Thanks a million ranchers..U have been a great part of my success..Lastly,hard work always pays off...Scjp is a pretty challenging certification & to acquire that we need to put in a good amount of hard work..

Thank u guys
Im planning on going ahead with my SCWCD..too thrilled to climb the next step!


Vidhya
16 years ago
Thanks ....Those were really good explanations
public static void main(String[] ar){
long [] [] a1;
long [] a2 [];
a2 = new long [3][];
a1=a2;

System.out.println(a2[1][0]);

}

why do i get a null pointer exception here?
don't pirimitve array elements take default irrespective of where they are declared.here a1,a2 are long arrays,so its array element a1[1][0] should be zero,right?
Why would this code produce a compiler error @ line 1?

class Color {}
class Red extends Color {}
class Blue extends Color {}
class A {
public static void main (String[] args) {
Color color1 = new Red(); Red color2 = new Red();
boolean b1 = color1 instanceof Color;
boolean b2 = color1 instanceof Blue;
boolean b3 = color2 instanceof Blue; //1
System.out.print(b1+","+b2+","+b3);
}}
interface I {String s1 = "I";}
class A implements I {String s1 = "A";}
class B extends A {String s1 = "B";}
class C extends B {
String s1 = "C";
void printIt() {
System.out.print(((A)this).s1 + ((B)this).s1 +
((C)this).s1 + ((I)this).s1);
}
public static void main (String[] args) {new C().printIt();}
}



Would'nt this code result in a compiler error cos it is trying to reassign a final member of the Interface I?
--------------------------------------------------------------------------------
Thanks Marc...i understand it better now...Does the same thing hold good for assignments b/w char & short also?
So from what was explained i understand that assigning a character to a byte or vice-versa is not possible w/o an explicit cast..Am i right?
is this assignment legal?

byte b2 = 'a';


We cant assign a character to a byte or short even with explicit cast..so will this work?
[ April 05, 2006: Message edited by: Vidhya Hari ]
Consider this code:

double v=Double.NaN;

if(v != v == Double.isNaN(v))

What will the above if statement return? what is the order of precedence for an equality operator..Also,does it work frm right to left or left to right?
I found this question on danchisholm,which says that valueOf() method can take a primitve argument as of version 1.4

class C {
public static void main(String[] args) {
Boolean b1 = Boolean.valueOf(true);
Boolean b2 = Boolean.valueOf(true);
Boolean b3 = Boolean.valueOf("TrUe");
Boolean b4 = Boolean.valueOf("tRuE");
System.out.print((b1==b2) + ",");
System.out.print((b1.booleanValue()==b2.booleanValue()) + ",");
System.out.println(b3.equals(b4));
}}


I learnt from K&B book that it takes a string representation of the primitve & not a primitve as such..

Can u pls clarify..
GC
class I {
private I other;
public void other(I i) {other = i;}
}
class J {
private void m1() {
I i1 = new I(), i2 = new I();
I i3 = new I(), i4 = new I();
i1.other(i3); i2.other(i1);
i3.other(i2); i4.other(i4);
}
public static void main (String[] args) {
new J().m1();
}}

Which object is not eligible for garbage collection after method m1 returns?

a. i1
b. i2
c. i3
d. i4
e. Compile-time error
f. Run-time error
g. None of the above


I think the object referenced by i4 is not eligible for collection cos it does not form an island of object.The instance variable refers to its own reference varible.But the answer says all are eligble for garbage collection. Is it becos i4 ia a local reference and is cleared off the stack when the method is exited?

Pls clarify
Hi,

u wont believe,i had this doubt haunting my mind for quite sometime,until i tried out a few codes..u call a variable a compile time constant if the compiler knows the value of that variable during compilation rather than at runtime as in most other cases..from ur code,

final int a=1: //compile time constant cos the compiler knows its value during compilation

final int b; //all the compiler knows is tht it is a final variable ,,the value is assigned only during runtime if u do not assign it in the same line it is declared..

b =2; // no use,compilation is over..so b gets the value only at runtime..

Since there is a limitation to switch case variables that they be final and int/int compatible,the compiler should be able to resolve its value at compile time itself to prevent compilation error.

hope i did not confuse u further..!
As far as i know, null does not fall into the category of keywords...it is just a literal ,like true & false..
Hi Balaji

Can u pls give me the website URL for Mugalson's SCJP1.4 simulator exam..

Thanks
16 years ago
I dont get why the answer is not C...the rules of object reference casting in Philip Heller/Simon Roberts book says,"when castin one class to another or one interface to a class,one of them should be a subclass or implement the other in order for the code to compile ".Here in the example i dont see a chance of it compiling 'cos A does not implement E but has been cast to E,which is wrong.Anyone who is really sure abt this concept,pls help.