File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Certification
»
Web Component Certification (SCWCD/OCPJWCD)
Author
I can access private variable??
Markandey Sahu
Greenhorn
Joined: Jun 29, 2006
Posts: 13
posted
Jul 11, 2007 05:58:00
0
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
class MyClass { String name = "hello world"; void show(){ System.out.println(name); } }
2nd class file name: Test.java
class Test { public static void main(String [] args){ MyClass obj=new Myclass(); obj.show(); } } [code] 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) [code] class MyClass { private String name = "my private variable "; private void show(){ System.out.println(name); System.out.println("MyClass private method"); } }
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
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35232
7
posted
Jul 11, 2007 07:00:00
0
Please do not post the same question multiple times. Let's continue the discussion in
this duplicate thread
, where you have an answer already.
Android apps
–
ImageJ plugins
–
Java web charts
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: I can access private variable??
Similar Threads
I can access private variable?? pl give me reason..
Top Level Class doubt
private final method
When do we need to declare a class as public?
Please Help !!! (package and accessibility)
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter