Balakrishna Thati

Greenhorn
+ Follow
since Mar 12, 2008
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 Balakrishna Thati

Thanks Isberg and Ritchie... we done it flawlessly atlast
12 years ago
Is this ok ? or any thing else missed ??

12 years ago
How about this ?

12 years ago
if the comparision is between the primitives, it again fall back to my option 1, that i stated earlier.

To conclude it finally, i changed the code little bit.

12 years ago
Thanks Ritchie,

Here is my code
12 years ago
Pragramatically how to show that there is only one instance of Static variable irrespective of number of objects...

I thought of doing it by
1. showing their values being equal.. But the counter argument is that the "having the same value doesn't sufficient to say they are from the same variable"
2. equating the static variable's hash code accessing it from different objects. But Hashcode can't guarantee uniqueness.

is there any other way to prove that irrespective of number of objects there is only one static variable exists for a Class.

-- KVT
12 years ago
Hi Vijay,

my question is about the requirement of downcast.

how a method declaration in base class will eliminate the need to downcast an object.

As you said, provide the method in base (remove the first comments) and try to compile. it is not getting compiling saying "incompatible types"

now provide the comments for the method in base class and remove the comments around casting. It is compiling and running normally.

my question is whether the thing mentioned in the book wrong or what??
Hi Santosh,

\u0038 is a unicode representation.

when java finds \u0038, it converts it to its equivalent value of 8.

so in when you run your code, f will print 8.0

observer this code


char c='\u0042';
int \u0042= \u0038;
System.out.println("x = "+B+", c = "+c); //B's unicode value is 0042 and 8's is 0038 (in Hex)



Here out put would be x=8, c = B

for unicode value look at
http://www.ssec.wisc.edu/~tomw/java/unicode.html
Hi,

This Q is from TIJ 4e, Interfaces, Ex-4

It is like this


Create an abstract class with no methods. Derive a class and add a method. Create a static method that takes a reference to the base class, downcasts it to the derived class and calls the method. In main(), demonstrate that it works. Now put the abstract declaration for the method in the base class, thus eliminating the need for the downcast.



How providing a abstract declaration for a method in base class will eliminate the need to downcast ??\

So i tried it with the following code


It still requires downcast. i checked the errara of this 4e.

But there is nothing regarding this.

Please clarify over this.
Thanks manoj and Cristian

Even though my doubt is cleared, i am more of feeling that this situation should be escalated at compile time itself rather than at runtime.


But don't know why they postponed it till run time. Any guesses ??
Hi James,

The show() method is public. So it will be available.

Then whats the issue with that. Why i am not been able to access it.

Even then The run time error is about the Class casting not with accessing a non-visible method.
Hi Mumtaz,

As you said

Child class do have all the method of parent class, but Parent class does not know of any method of child class thats why it can not be downcasted to child class unless the object it referred to is of Chile class.



so based on this, the following code should compile and run properly


But its throwing the same Exception.
Hi,

One of my friend told me that

Assertion checking can be controlled on a class, package, or package hierarchy basis.

can any one explain with an example how can we do this ??

or refer me to a good link


Hi,

i am performing the following downward casting.

I am thinking that the Child class will have all the methods of the Parent class so when a Parent object is downward casted to Child class, we should be access methods derived from the parent class.

Here is my code..

The above code altering between Block 1 and Block2, compiling normally but Block1 code throwing an exception java.lang.ClassCastException.

Why is it??