sandeeep shinde

Greenhorn
+ Follow
since Aug 26, 2009
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 sandeeep shinde

Thanks for your replies guys. I got the point.
14 years ago

uj nossnahoj wrote:

That's right, there's no restriction, and my point is that this is necessary. Otherwise many classes would be forced to expose implementation detail to the outside (by raising the access rights of variables and methods that better would stay private). And this would be contrary to encapsulation and information hiding.



That is the point. Why would classes be forced to expose implementation detail if we put the restriction?
14 years ago
Thanks a lot for your replies uj nossnahoj .
14 years ago

Campbell Ritchie wrote:No, there is no restriction on access to private members between different instances of the same class. You know about it. You wrote the class knowing where there is access to private members of other instances.



No I didn't know about it. I have taken this snippet from somewhere else and was not able to understand it.
14 years ago
Ok. So when methodB is called the i2 has reference to same object as startingI. But when I am doing i2 = i2.intvalue ; the reference to the literal 25 is getting assigned to i2.
Am I correct?
14 years ago

uj nossnahoj wrote:

The reason for this behavior is quite obvious if you think about it. Otherwise many (or even most) classes would have to expose preferrably private variables and methods publicly in order to be implemented. This would be a serious blow to the concepts of encapsulation and information hiding in Java.



Does this mean in general that there is no restriction on accessing data between instances of the same class?
Still I don't get the point. Could you please elaborate on this?
14 years ago
Please take a look at the code below



The output produces "false true" .
If the values in the wrappers being compared are in the range -128 to 127 the == should return true.
But how does it return false here.
If I comment the statement i2 = i2.intValue(); the == returns true.
Can somebody please guide me on this?
14 years ago
Thanks a lot for your replies guys.
So it means that the private variables just cannot be accessed from other classes.
If the instance is created in the same class itself the private variable of that instance can be accessed directly.
Please correct me if I got it wrong.
14 years ago
Hi,
Please have a look at the code below.



This code compiles and runs. How am i able to access the name variable directly even if it is a private variable.
e.g the code p.name = "andy" should throw compilation error. Please giude me.
14 years ago

Steve Luke wrote:
There is actually only one instance here (just one building), in the analogy the floors don't represent different instances, just type definitions.



I think that sums up for me. I think I am on a little firm ground now.
Thanks a lot to all of you for the replies.
14 years ago
If I am not wrong whenever a class is instantiated all the superclasses of that class are also instantiated.
And when the method is called on that instance( i.e the Horse class here) the search for the method begins from bottom to top.
The method is exceuted on the instnce of whichever class or superclass the method is found on..

The analogy of building made it pretty clear.

Please correct me if I am wrong.
14 years ago

Sebastian Janisch wrote:Think about it. After all private methods are always (indirectly) invoked from outside the class, unless your program is a single class application.

The client calls a public method, the public makes use of private helper methods.



This is behaving as if I have instantiated an Animal object and called the public method on it.
But it is actually an inherited method.
I am confused about inheritance. What does it actually mean to inherit a method.
Is it something like callEat() method code being copied to the Horse class?
14 years ago
Hi ,
Please have a look at the code below.


When I run TestPoly the "In Animal eat" output is dissplayed. But eat() is a private method of class Animal.
Horse class will inherit the callEat() but not eat() method. Now I am using reference of Animal but object of Horse class.
So the method callEat() should be called on Horse class. And as it has not inherited the eat() class it should not run successfully.

Can somebody please explain why it is running successfully?
14 years ago