Win a copy of Terraform in Action this week in the Cloud forum!

Anna s Iyer

Greenhorn
+ Follow
since Aug 21, 2000
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 Anna s Iyer

Just to add...
Consider your directory as in the explorer C:\Java\RancH and you are supplying argument to your program c:\java\ranch and here are the results.
f.getAbsolutePath() writes c:\java\ranch and
f.canonicalPath() writes C:\Java\RancH
Hope that helps to understand the mear difference.
Anna S Iyer.
Can't I have a static method or static variable inside a non static inner class?.
Am I missing something very obvious?.
Thanks,
Anna S Iyer.
Aaron,
You didn't call the settest() method!. Call it with a parameter and then only the instance variable i will get set to 3.
Hope that helps,
Anna S Iyer.
Shalini,
Methods have no return type (void) are also eligible for overriding. Please refer this
Shadowing - One place shadowing comes up is when you have field names and parameter names that are the same, and you want to use the parameters to set the fields:
int a; //instance variable
public void f(int a) {
a = a;
}
This doesn't change the instance variable, because the parameter "a" shadows the field "a", that is, the parameter name blocks access via a simple name to the field name. This has the work around with the usage of "this" variable. I don't think we need to mix up shadowing with overriding and hope this helps of shadowing. Please pass your comments.
Travis,
orclass2 or2 = new orclass2();
or2.ormeth1(200);
I don't think we can say here overriding happens. It just invokes the method ormeth1 defined in the class orclass2 goes by the object or2 construction.
The reason why I am NOT saying this is overriding is that -
For example - Add modifier static to both the methds ormeth1 in both the classes and run the program. It will write 200. But keep in mind that static methods cann't be overridden. So hidden takes place.
Does it make sense?.
-----------------------------------------------------------------
orclass1 or12 = new orclass2();
or12.ormeth1(300);
ONLY here overriding happens because it supposed to display the method in the class orclass1 as the way the object or12 constructed. But it invokes the method in orclass2 and hence overriding takes place.
Appreciate your explanation and comments.
Thanks,
Anna S Iyer.
Consider the following code and comments.

So, same method name, arguments and return type are the definition for a method to get qualified for overriding. The actual overriding happens and determined in the way we are creating the objects for the classes.
Am I understanding it correctly?. Please correct / confirm me.
Thanks,
Anna S Iyer.
Lakshmi,
Look at this and will be very helpful.
Anna S Iyer.

[This message has been edited by Anna s Iyer (edited October 27, 2000).]
The type of the Expression must be char, byte, short, or int OR a compile-time error occurs.
So it cann't be any variable(double, float) unless with explicit casting.
Hope this helps,
Anna S Iyer.

The method reference through "aref" results in Lookup.f being called, but the field reference obtains A.x. The actual class of an object determines which instance method is called. But for fields, the type of the reference is used (here it's aref, of type A).
Here is the output.
Lookup.f
37

Could anyone explain why this strange behaviour?.
Thanks,
Anna S Iyer.
Here is my explanation goes.
Though you are able to compile the following code but still it hides the static method and NOT overrides it.
Please run the following code.
If it is really overrides the static method then it should have printed "Aru" right?. But it prints "Aruna". And implies that it just hides and NOT overrides static method.

Hope this helps,
Anna S Iyer.
[This message has been edited by Anna s Iyer (edited October 20, 2000).]
Check out the spelling.
Anna S Iyer.
The answer should be C and infact there should not be any space between Hello and There .
Though you are passing copy of the objects a and b to the convert method - only x is getting operated and hence the pool value for a is modified to HelloThere.
Since y is just a reference assignment inside the method and the scope is only within the method convert and hence the result.
Hope this helps,
Anna S Iyer.

When I add static modifier to the final variable a then I am getting compilation error and when it gets initialised the error goes off and runs by taking out the constructor and is fine(Cann't change the final value).
Could any one help me in understanding the behaviour of final with static?
Thanks,
Anna S Iyer.
When a simple type is passed to a method, it is done by use of call-by-value. Objects are passed by use of call-by-reference.
Also run the following sample and will make it simple.

Hope this helps,
Anna S Iyer.

[This message has been edited by Anna s Iyer (edited October 14, 2000).]
Here is the order in which widening conversion takes place.
byte to short, int, long, float, or double
short to int, long, float, or double
char to int, long, float, or double
int to long, float, or double
long to float or double
float to double

In your case long is first looks for float and if not goes to double.
Hope this helps,
Anna S Iyer.
1. Using Interface you can force what a class MUST do and not how it implements.
2. Interfaces are designed to support dynamic run time method resolution. Means Interface disconnects the definition of methods from the class hierarchy. Interfaces are totally different hierarchy from classes.
Hope this helps,
Anna S Iyer.