Link to home
Start Free TrialLog in
Avatar of mdoland
mdoland

asked on

int cannot be dereferenced

I have an application where I from the class with the main method want to set certain static values in a class X. X extends an abstract class Y. I can set a similair value in Y. What is wrong?

I get compilation errors saying:  int cannot be dereferenced

Avatar of for_yan
for_yan
Flag of United States of America image

Can you post the code to make it more understandable?
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Where I saw this kind of diagnostic cime up in compilation is when
you try to call the method on primitive type, like

int i;

String s = i.getName();

This cannot work because you cannot call methods on primitive type

Avatar of mdoland
mdoland

ASKER

Does this work? Should it work?
public class A_and_B {
    public static void main(String[] args) {
        X.aa = 2;
    }

}
abstract class Y {
    public abstract void goTo();
}
class X extends Y {
      static int aa = 1;

      public void goTo(){

      }
}

Open in new window

It is the same code I posted? Did you change anything - I don't see any changes.
Yest, I tried it - it does compile, and should run also, why not?
Avatar of mdoland

ASKER

I changed it slightly ... I put the aa in the other class.
Of course this one also compiles wihout any problem -
this one is even less controversial than prvious versio
aa is in class X and you just change X.aa = 2 -
it is even more obvious than the previos case.

But they both compile without any problem.
Try for yourself.

public class A_and_B {
    public static void main(String[] args) {
        X.aa = 2;
    }

}
abstract class Y {
   
    public abstract void goTo();
}
class X extends Y {
               static int aa = 1;
      public void goTo(){

      }
}

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial