Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program.cs
- public class Program {
- public static User user = null;
- public static void main() {
- //stuff
- }
- }
- //User.cs
- public class User {
- //whatever you have in here
- public String aMethodInUser() {
- //stuff
- }
- public static int totalUsers() {
- //return total users (static method)
- }
- }
- //ANY other file can now access user
- public class MyOtherClass {
- public int doSomethingCool() {
- //you can then access your user object like this;
- System.out.println(Program.user.name);
- doSomethingElse(Program.user);
- Program.user.aMethodInUser();
- //and if User has any static methods, you don't need a reference
- //to any particular instance, and can do things like;
- System.out.println(User.totalUsers());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement