Vaibhav Aggarwal

Greenhorn
+ Follow
since Sep 12, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Vaibhav Aggarwal

Hi

I cleared the SCJP 1.5 exam last week. I got a score of 86%. I studied only from one book and that was by Kathy Sierra, Bert Bates and gave lots of mock exams. Kathy Sierra, Bert Bates have written a great book. It has helped me gain a better understanding of java besides passing the exam.

Vaibhav Agarwal
SCJP 1.5
16 years ago
Check out the below code The ouput for above code will be.


You will see that when we use "this" then we are refering to the current instance of the class. So while the display method changed the value of the local variable, updateInstanceVariable method updated the instance member of the current object.
[ September 24, 2007: Message edited by: Vaibhav Aggarwal ]
16 years ago
Hi

U can convert int into float by implicit casting . Example
Output would be
16 years ago
Thank you Dhaval,Jesper and Rob . I had no idea that, long to a float is a widening primitive conversion and that both of them store numbers in a defferent format.
16 years ago
Hello,

I am not able to understand the following code :-

class Demo {

public static void main(String[] args){
long m =20l;
float n =30f;
n=m;
System.out.println("The value of n is "+n);
}
}

Problem is : long is 64 bits and float is 32 bits, but when we assign a long to float it doesn't give a error, while when we want to do a narrowing casting we should have to do explicit cast.

Vaibhav
17 years ago
Congrats !! and Yes, it's a great book even i am preparing for the exam by reading it.
17 years ago
Thanks for replying. Your code has helped me understand the concept.
17 years ago
Hello,

I am writing a code could someone help me understand it.

class SuperClass{

void display(){
System.out.println("In SuperClass");
}
}

class SubClass extends SuperClass{

void display(){
System.out.println("In SubClass");
}

public static void main(String[] args){
SuperClass obj = new SubClass();
obj.display();
}
}

1) Is this example of "Runtime Polymorphism" ?
2) If it so then why is it called so - I can't understand that if we writing in the code that "obj = new SubClass();" than the compiler would know that "obj.display()" would call the method of SubClass, so shouldn't it be "compiletime polymorphism".
17 years ago