I was wondering if it is possible to use a sub class to add more variables to a super class and be able to call that variable from the super class.
Here is relevant code to the project I am working on, and was hoping to get this figured out.

Simple class, I will be adding more to it after I can get this to work.

Code:
public class MDMats extends iu{

   public static final iu ironMDMat = new iu();
}


Now here is the iu class that the previous code is referring to:


Code:
public class iu
{
  public static final iu a = new ja();
  public static final iu b = new iu();
  public static final iu c = new iu().f();
  public static final iu d = new iu();
  public static final iu e = new iu();
  public static final iu f = new of();
  public static final iu g = new of();
  public static final iu h = new iu().f();
  public static final iu i = new ae();
  public static final iu j = new iu();
  public static final iu k = new iu().f();
  public static final iu l = new ja();
  public static final iu m = new iu();
  public static final iu n = new ae();
  public static final iu o = new iu();
  public static final iu p = new iu().f();
  public static final iu q = new iu();
  public static final iu r = new iu();
  public static final iu s = new ae();
  public static final iu t = new iu();
  public static final iu u = new iu();
  public static final iu v = new iu();
  public static final iu w = new iu();
  public static final iu x = new iu();
  public static final iu y = new iu();
  private boolean z;

  public boolean d()
  {
    return false;
  }
  public boolean a()
  {
    return true;
  }
  public boolean b() {
    return true;
  }
  public boolean c() {
    return true;
  }
  private iu f() {
    this.z = true;
    return this;
  }
  public boolean e() {
    return this.z;
  }
}


I am trying not to modify the existing code if at all possible as I am making a mod that is compatible with a mod loader.

Any and all help is appreciated, thanks. Very Happy

P.S. If you need more data, just let me know and I will get it for you.
The way you are trying to do it, now. This is actually a pretty awful way to do it, but I don't fully know your circumstances, so... My best suggesting is to use Java.Util.List<iu>, and add iu elements to that list.
What exactly are you trying to accomplish by using subclasses this way? It's not clear what you are doing just from this code snippet.

Also, instead of doing this:

Code:
  public static final iu c = new iu().f();

I would add a constructor in class iu that takes a single boolean argument and sets the z member to that value, and then change the above line to this:

Code:
  public static final iu c = new iu(true);

Here's what that constructor could look like:

Code:
  public iu(boolean z) {
    this.z = z;
  }
The second code is from Notch's original .class files from Minecraft, I will not edit it because that could cause other mods to break.
All the variables are single letters like that? I can only assume it's intentional code obfuscation?
Sonlen wrote:
I was wondering if it is possible to use a sub class to add more variables to a super class and be able to call that variable from the super class.


No, and what you are asking doesn't make sense anyway. If the super class doesn't know about the variable, how can it use it? You cannot have an abstract field.

Now, you can override those methods like e() to return whatever value you want instead of z, but whether or not the super classes uses the method instead of directly accessing the field isn't something you can change. Despite z being private, though, you *CAN* modify it.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement