Results 1 to 5 of 5
- 01-02-2012, 08:48 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
Calling private int from another java file
Okay, i know this is probably a simple question. But i would like to call a private int from another java file.
For example, say i have a file named One.java and it has
.Java Code:private int shopId = 0;
Is there anyway i get call this int in a different file without making it public or static?
- 01-02-2012, 08:54 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Calling private int from another java file
That's exactly what the word 'private' means: nothing outside of that class can touch those privvy parts. You can define a public method though:
That method is called a 'getter' or 'accessor', so other objects of other classes can get the value of your private variable.Java Code:public int getShopId() { return shopId; }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-02-2012, 08:57 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
Re: Calling private int from another java file
Where exactly do i put this? Under private int shopId = 0; or in the file requesting it?
- 01-02-2012, 09:19 PM #4
Member
- Join Date
- Dec 2011
- Location
- Croatia,Zagreb
- Posts
- 21
- Rep Power
- 0
Re: Calling private int from another java file
u have to put it in class where your variable is.
Java Code:public class Something { private int shopId; public int getshopId(){ return shopId; } }
- 01-02-2012, 09:22 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Calling private int from another java file
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
calling a .exe file from java code
By ingudam in forum New To JavaReplies: 1Last Post: 04-04-2011, 12:41 PM -
calling python file from java
By cool in forum AWT / SwingReplies: 3Last Post: 11-11-2010, 03:50 AM -
Problem with calling php script from java file
By eldushyant in forum Advanced JavaReplies: 1Last Post: 04-28-2010, 12:56 PM -
calling a jar file from within java application
By robby14 in forum Advanced JavaReplies: 3Last Post: 03-10-2010, 08:11 PM -
excecuting a jar file by calling a java class
By Lavanya.vitria in forum Advanced JavaReplies: 1Last Post: 12-13-2008, 12:11 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks