File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes I can access private variable?? pl give me reason.. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "I can access private variable?? pl give me reason.." Watch "I can access private variable?? pl give me reason.." New topic
Author

I can access private variable?? pl give me reason..

Markandey Sahu
Greenhorn

Joined: Jun 29, 2006
Posts: 13
hi all,
I can access the private variable. how?? i am showing now
write these two class and compile and run
1st class file name:MyClass.java

2nd class file name: Test.java

compile and run you will get out put:
hello world

now magic is here make following changes in MyClass.java

(means now your MyClass.java become following)

now be careful compile only MyClass.java file not the Test.java file
after compilation run Test class using command (java Test)

now you will get output:
my private variable
MyClass private method

Note: Please run the following application in your console
don't use any editor .. eclipse or other else

if you get reason for this behavior pls answer me
thanks in advance
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Hi,
you are off topic, here. However, consider that the visibility check is done by the compiler and NOT at runtime.


SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="http://www.enthuware.com" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I don't see what's off-topic about this. Seems a perfectly reasonable beginner question, doesn't it?

Basically, if you change and re-build part of an application, and not other parts that would be affected, you can mess it up in a variety of ways, including this one. That's a mis-build and not really terribly interesting beyond that, I think.

In situations where you want to prevent modified code being put into your application, Java has various protection mechanisms available, like SecurityManager, Jar signing, and all sorts of things that I'm afraid I never use, so can't advise further on.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24050
    
  13

Discussed to death here. Can you please let us know who is putting this bee in your bonnet, so we can look out for it in the future? Both people who posted this question posted it multiple times in multiple forums, so I'm thinking it's a job interview question or something.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: I can access private variable?? pl give me reason..
 
Similar Threads
package problem
K&B(SCJP5) page no:769.......
I can access private variable??
private final method
Please Help !!! (package and accessibility)