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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:12:00+00:00 2026-06-09T00:12:00+00:00

I have a sample interface public interface SampleVariables { int var1=0; int var2=0; }

  • 0

I have a sample interface

 public interface SampleVariables {
int var1=0;
int var2=0;
}

and I want to use var1 and var2 across multiple classes i am trying to do this using

public class InterfaceImplementor  extends Message  implements SampleVariables{

private int var3;

public int getVar1(){
    return var1;
}

public void setVar1(int var1){
    SampleVariables.var1=var1; // ** error here in eclipse which says " remove final modifier of 'var1' " Though I have not defined it as final
}

public int getVar3() {
    return var3;
}

public void setVar3(int var3) {
    this.var3 = var3;
}

}

where class Message is a pre-defined class which I try to use and I cannot define var1, var2 in the class Message.

Is there a better way to do this? Or am I missing something really simple ?

  • 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-09T00:12:01+00:00Added an answer on June 9, 2026 at 12:12 am

    All fields in an interface are implicitly static and final, hence your warning above. See this SO question for more details.

    It seems to me that you want a base class with these variables, but as you’ve noted you can’t do this since you’re deriving from a 3rd party class.

    I would not derive from that 3rd-party class, since you don’t control its implementation. I would rather create a class that wraps it and provides your additional functionality. That gives you a level of comfort that if/when that 3rd-party class changes, you can limit the scope of the changes that you have to subsequently make.

    Unfortunately Java doesn’t support mixins, which is what you’re trying to achieve here.

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

Sidebar

Related Questions

This is probably a simple misunderstanding on my part. Have a simple interface: public
I have created the simple web service. Code: [ServiceContract] public interface ITsdxService { [OperationContract]
Does anyone have sample code, or a tutorial which demonstrates how to use Grappa
First, a little explanation about my situation: I have a sample interface which is
I have custom control and I have interface this control exposes to it's users.
Have following code: public interface ITest { string St1 { get; } } public
I want to test which interfaces a class/interface is implementing. So I have a
We have several classes in place for our CMS and I'm trying to get
In the following code sample I have an Async Calculator class. This is injected
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,

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.