Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:45:17+00:00 2026-05-27T02:45:17+00:00

i have a class main { Class1 class1=new Class1(); class1.function1(); } class Class1 {

  • 0

i have a class

    main {  
      Class1 class1=new Class1();  
      class1.function1(); 
    }


     class Class1 {   
        int abc=1;   
        ArrayList<Class2> class2s=new ArrayList<Class2>(); 

        int function1() {
          class2s.add(new Class2(asd));
          abc=555;   
        }    
     }

     class Class2 {   
        int functionx() {
          Log.e("abc?", ""+PARENT???.abc);   
        } 
     }

How can I get the caller Class’s variable, say abc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:45:17+00:00Added an answer on May 27, 2026 at 2:45 am

    You could pass the caller as an argument, like so:

    int functionx(Class1 caller) {
      Log.e("abc?", ""+caller.abc)
    }
    

    and call it with

    Class2 cls = new Class2()
    cls.functionx(this)
    

    As long as abc is visible to Class2. Otherwise there is no direct means of knowing your caller in Java. The variable class2s implements a uni-directional relationship between Class1 and Class2. So you can only navigate from Class1 to Class2, not the other way around.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: class Program { static void Main(string[] args) { new
I have a main class in a program that launches another class that handles
I have a question about the 'Event Dispatch Thread'. I have a Main class
I have a small Java test app in Netbeans where the main() class reads
I have following code public class TEST { public static void main(String arg[]){ try
I have a file called hellowf.cs class MyFirstApp { static void Main() { System.Windows.Forms.MessageBox.Show(Hello,
I have the following code: public class Test { public static void Main() {
I have a little console C# program like Class Program { static void main(string
Say hypothetically I have a class... class Main { $prop1 = 2; $prop2 =
I have an Android activity called main.java and BPMClass.java class. I need to call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.