Amar Shrivastava

Greenhorn
+ Follow
since Oct 17, 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 Amar Shrivastava

A static mehtod cannot override an inheritted instance method but it can hide a static method. This is because static methods are class specific and overriding is associated with objects not class(i.e. only instance methods are overridden).

Overridden method calls are resolved at runtime depending on the type of object being referred at runtime but binding of method call to method implementation is done at compile time if the method is static or final.

So defining a method as static final helps to call the method without instanciating the class(i.e. because it is static) and also prevents changing its implementation(i.e. because it is final).
18 years ago
Yes, Layne you are absolutely right. I misunderstood the Question.

If the number field in C was not private then D would have inheritted that field but NOT the field in A.

Thanks for explanation.
[ October 21, 2005: Message edited by: Amar Shrivastava ]
18 years ago
You are absolutely right Roel. Sorry, the final modifier is the odd one. Thanks for reminding.
18 years ago
Layne, I suppose that here in this example it is the modifier private in class C which is the main culprit for the error in class D.

This field in C is hiding the superclass field and so not inheritting it,
and since it is private it is not letting class D to inherit this field.
18 years ago
The error is beacuse class D extend C and inherits all members except which are private, final,overridden or hidden.

A subclass does not override fields of superclass, but it hides them.The subclass can define fields with the same name as in the superclass. Doing this hides the superclass field and hence it is not inheritted.
In subclass we can use superto access supeclass members(including hidden fields). If the hidden field is static then it can also be accessed by the superclass name.
18 years ago
Early binding is not only method signature resolution at compile time .It also binds the exact method implementation (method body) with the method call at compile time. This can only happen if the compiler can determine( looking at the modifiers associated with the member of the class) that there would be no ambiguity at runtime, no matter which type of object being referred by the reference.
So, if the above thought is right :roll: then early binding should occur with only private, static and final methods. Hence, early binding has nothing to do with overloaded methods. It is the modifier which helps determine whether it is early binding or late binding.

[ October 18, 2005: Message edited by: Amar Shrivastava ]
[ October 18, 2005: Message edited by: Amar Shrivastava ]
18 years ago
Not only private members.
Members which are hidden and overridden are also not inheritted by the subclass.
The simplest rule to find which memers are inheritted is:

All members of the superclass which can be accessed by their simple names(as if they are the members of this subclass) in the subclass are inheritted.
18 years ago
There is a little more confusion now!!!

What is meant by "Binding"?

Is it only method signature resolution or is it the binding of method signature with actual method implementaion(i.e. method body)?
18 years ago
But how could you ever say that the overloaded method will not be overridden in the subclasses.

Let's say:


In this case looking at class A alone which does not no that it has a sub class and the class Client uses a class A reference and calls a method x.
Now how could this be resolved at compile time.
[ October 18, 2005: Message edited by: Amar Shrivastava ]
18 years ago
But how could you ever say that the overloaded method will not be overridden in the subclasses.

Let's say:

public class A{

int x(String s){...}
int x(int i){...}
void x (String s, int i){}
....
....
}

public class B extends A{
int x(String s){...}
int x(int i){...}
void x (String s, int i){}
......
....
}

class Client {
public static void main(String []args){
A a= new B();
a.x("java");
}
}

In this case looking at class A alone which does not no that it has a sub class and the class Client uses a class A reference and calls a method x.
Now how could this be resolved at compile time.
18 years ago
HashMap class is not thread-safe nad permits one null key,the HashTable class is thread-safe and permits non-null keys and values only.
The Thread-safety that <i>HashTable</i> class provides has a performance penalty. HashTable class is a legay class that has been retrofitted to implement the Map interface.
18 years ago
Hi All

During my recent interviews I was asked about Polymorphism and early binding and late binding. Every time I said that overloaded methods implementations are binded dynamically during runtime until the method is static or final(private are implictly final). But every time I was told by the interviewers that overloaded methods are early binded.
Could you please suggest what is correct with overloaded methods and Why?
[ October 17, 2005: Message edited by: Amar Shrivastava ]
18 years ago
Hi All

During my recent interviews I was asked about Polymorphism and early binding and late binding. Every time I said that overloaded methods implementations are binded dynamically during runtime until the method is static or final(private are implictly final). But every time I was told by the interviewers that overloaded methods are early binded.
Could you please suggest what is correct with overloaded methods and Why?
[ October 17, 2005: Message edited by: Amar Shrivastava ]
18 years ago