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 7184349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:11:00+00:00 2026-05-28T18:11:00+00:00

Is there a Java equivalent – specifically on Android – for VB.NET’s Static keyword?

  • 0

Is there a Java equivalent – specifically on Android – for VB.NET’s Static keyword? For those not familiar with VB.NET, take the following code snippet…

Sub MyFunc() 
    Static myvar As Integer = 0
    myvar += 1
End Sub 

The Static keyword makes it so myvar retains its value between subsequent calls to MyFunc.

So after each of three calls to MyFunc, myvar’s value would be: 1, 2 and 3 .

How do you make a cross-call persistent variable within a method in Java? Can you?

  • 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-28T18:11:02+00:00Added an answer on May 28, 2026 at 6:11 pm

    No. Within a method, Java doesn’t have something which can be remembered across various calls.

    if you want to persist a value across multiple calls of a method, you should store it as instance variable or class variable.

    Instance variables are different for each object/instance while class variables (or static variables) are same for all the objects of it’s class.

    for example:

    class ABC
    {
        int instance_var; // instance variable
        static int static_var; // class variable
    }
    
    class ABC_Invoker
    {
        public static void main(string[] args)
        {
            ABC obj1 = new ABC();
            ABC obj2 = new ABC();
    
            obj1.instance_var = 10;
            obj2.instance_var = 20;
    
            ABC.static_var = 50; // See, you access static member by it's class name
    
            System.out.prinln(obj1.instance_var);
            System.out.prinln(obj2.instance_var);
            System.out.prinln(ABC.static_var);
            System.out.prinln(obj1.static_var); // Wrong way, but try it
            System.out.prinln(obj2.static_var); // Wrong way, but try it
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a Java equivalent to .NET's App.Config? If not is there a standard
Under .net (specifically C# really), is there an equivalent to Java's DataSource class? I'm
Is there a Java equivalent to .NET Reflector ? Edit: more specifically, decompiling is
I am looking for a Java equivalent to .NET's Snippet Compiler. Is there any
Is there an equivalent to Java's null layout in Android? Basically I want to
Is there a .NET equivalent of Java Web Start? I want a one-click, from
Is there a.NET utility class equivalent to java.util.Arrays.hashCode() for arrays of intrinsic types such
Is there a Java equivalent for ASP.NET Membership?
I am converting the following C# code to Java. Is there a Java equivalent
Is there an equivalent of Java Message Driven Beans for .Net?

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.