Hi, I have a java program with quite a lot of classes. I'm facing a problem with accessing some variables from another class. May I know how to I access it? Is it possible?
Sunshineserene
0
Junior Poster
Recommended Answers
Jump to PostDeclare that variable public, or better have public get methods:
class ClassA { private int value = 0; public int getValue() { return value; } }
class ClassB { public static void main(String [] args) { ClassA cla = new ClassA(); System.out.println(cla.getValue()); } }
All 3 Replies
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
jon.kiparsky
326
Posting Virtuoso
tong1
22
Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.