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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:07:20+00:00 2026-06-13T02:07:20+00:00

I know that interface can have only static and final values implemented inside it..

  • 0

I know that interface can have only static and final values implemented inside it.. But is there any loophole by which I can change the value of
a variable using interface?? The question may be absurd, but I m helpless since its my requirement. Here is the example piece of code..

public interface I {
    int val = 1;  
    int changeValue();

}

Class A implements I{
    int changeValue(){
        val = 2 ; 
        return 0;
    }
}

How to change the value of ‘val’ using interface?
Can I do something similar to:

val = changeValue();

Is there anything equivalent to do this functionality in an interface?

  • 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-06-13T02:07:21+00:00Added an answer on June 13, 2026 at 2:07 am

    You cannot. Interface variables are static and final by default.

    A final variable is a variable that cannot be changed during the life of the object.

    A static vairable is a class variable – it means there is only one value of it for all instances of the class (or interface in this case).

    Thus – you only have one value for I.x – and this value cannot be changed.


    What you might want to do, is define methods in your interface:

    int getVal();
    void setVal(int val);
    

    And make the implementing classes implement the methods – so you will be able to use the variable with the getVal() and setVal() methods.

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

Sidebar

Related Questions

I know that you can't have a constructor in an interface, but here is
As you know, OAuth can support RSA-SHA1 Signature. I have an OAuthSignature interface that
I know that an interface does not have a body, just a method definition.
I know that Phonegap has an event for back button, but it's only available
I know that in Java, someone can include constants inside interfaces by declaring them
I know that you can't update UIView from background view. But not sure if
I need to make so that my application can have only one instance running
I am still not so familiar with interfaces in Java. I know that interface
I know nothing about Xcode, except it's a Developer interface from Apple that actually
I know that this sort of question has been asked here before, but still

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.