goel Ashish

Greenhorn
+ Follow
since May 14, 2011
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 goel Ashish

Paul Clapham wrote:

goel Ashish wrote:

Paul Clapham wrote:There might be a way to do that, but the "=" operator isn't that way.


so does that mean that floating point no.s cant be assigned to any other type like char, int, byte etc. without any explicit cast but the other types can be assigned to one another if we are widening.



No. It means that there might be a way to assign the 32 bits which represent a float value to an int, but that the "=" operator isn't that way. It doesn't say anything at all about assigning things to char, it doesn't say anything about assigning values of other types to one another, and it doesn't say anything about widening.



So what all are legal assignments in java using = operator? I am not clear about the concept
9 years ago

Paul Clapham wrote:There might be a way to do that, but the "=" operator isn't that way.


so does that mean that floating point no.s cant be assigned to any other type like char, int, byte etc. without any explicit cast but the other types can be assigned to one another if we are widening.
9 years ago
But internally both are stored as a bit pattern, so cant integer interpret the bit pattern as an integer?
9 years ago
I have a little confusion in assignment concept in java.
What I have understood is compiler only gives error when we try to assign a variable of larger bits to small bit size variable(narrowing) like long to int. And doesn't gives error if we do widening.
But in the example below :-

Compiles fine while being a narrowing.

but this one below :-


gives compiler error while both float and int are 32 bits.
Why is that??
9 years ago

Ramakrishna Gummadi wrote:

Campbell Ritchie wrote:No, static members are not polymorphic. In fact you ought only to call static members by className.memberName, rather than on an object name.



yup.. static members called with help of classname.
But what about following code... here staticmethods luks like overriding ?

class Foo {
public static void classMethod() {
System.out.println(“classMethod() in Foo”);
}

public void instanceMethod() {
System.out.println(“instanceMethod() in Foo”);
}
}

class Bar extends Foo {
public static void classMethod() {
System.out.println(“classMethod() in Bar”);
}

public void instanceMethod() {
System.out.println(“instanceMethod() in Bar”);
}
}

class Test {
public static void main(String[] args) {
Foo f = new Bar();
f.instanceMethod();
f.classMethod();
}
}



Who says its over-riding?? When you execute the statement f.classMethod(); , It executes the foo's class method Which is not at all over riding, for in overriding subclass method is executed.
10 years ago
@campbell Maybe I understood the same thing which you explained. Now your post and concept both are clear. Thnks.
10 years ago

Campbell Ritchie wrote:More likely the compiler binds the declared type to the object for static members, or fields, or private instance methods, and permits the JVM to bind at runtime for non-private instance methods.


Didn't understood what you explained . Can you elaborate?
10 years ago
As far as i have understood this thing the flow in like that:-

At compile time the function call is binded to the function of that class of which type reference variables is.
Now at run time the jvm first sees if the function can be overridden or not. If it can be then jvm checks if is being overridden or not, If yes then it executes the overridden method. Else it executes the compile time binded method.

Am I right now??
10 years ago
I am still confused.
Isn't it like :- During compilation binding of method call is done in accordance with the type of reference variable but at the runtime jvm will execute that function of which object is created. Using this concept in the above example :- private method eat is not inherited and therefore callEat method's call to eat function should execute the eat method of horse class.
10 years ago
Why does the following code prints "animal eating" :-


And changing the modifier of eat method in Animal class from private to public results in printing :- "horse eating"
10 years ago
I understand most of these terms but not as a general oo concept. Its fine and as you suggested i will look more into some of the material and will post the my question again.
10 years ago
Hi,

Can anybody give me general definitions for the following object oriented concepts :- Encapsulation, inheritance, polymorphism, abstraction, decomposition, cohesion, coupling.
And then relate this concepts specifically with java language with examples ?

I know about these terms but have no clear definition for interview purpose. So any help from you guys is appreciated.
Thanks in advance.
10 years ago

Federico Cardelle wrote:
The order of execution is
1.the constructor of the superclass (in this case is is Object() and it does nothing)
2.initialization of instance variables
3.the code in the constructor



If it is like that then what happens when we dont initialize a final variable during declaration and initialize it inside a constructor??
10 years ago
1. Why a final instance variable needs to be initialized if we dont even use it in our code? why dont compiler provides a default value to it?
2. Why the following code prints 10 ?


because afaik constructor is the first thing that gets executed in a class before the initialization of instance variables.
10 years ago