0

I have a Java Package exec. It has two classes in it A and B.

In A class, I'm trying to access a static function of B. Now, Eclipse throws an error that "B cannot be resolved"

Again, the same error comes when I try to access a function of B from ObjB(An Object of B).

Is there anything that I should try to fix in Eclipse?

package exec;
public class A{
 public static void main(){
   B.fun1();
  //Error thrown here
   B Objb = new B();
   Objb.fun2();
  //And here
 }
}

And, this is the Class B

package exec;
public class B{
  public static void fun1(){
    }
  public void fun2(){
    }
}
ItsMeGokul
  • 403
  • 1
  • 5
  • 16
  • 1
    "*I have a Java Package A*" - `Package exec;` - `public class A{` - Please get your naming straight. What is a package? What is a class? – Turing85 Jan 10 '18 at 16:08
  • The code you posted does not compile, as "Package" is capitalized. Also, the code described and the code posted do not match at all. Consider posting all of your code please. – rmlan Jan 10 '18 at 16:08
  • 1
    *Java Package A* no, it is a class – Ravi Jan 10 '18 at 16:08
  • Nowhere in class B are you trying to access a static function of Class C. Please review [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – rmlan Jan 10 '18 at 16:10
  • Fixed the namings and typos. My code is too elaborate for the problem that I mentioned, So I kind of created this code myself. – ItsMeGokul Jan 10 '18 at 16:11
  • 1
    Right, the "created code" would be an MCVE. I still don't see a class C. Do you need to edit the description again? – rmlan Jan 10 '18 at 16:12
  • Apparently, searched further and found this post. https://stackoverflow.com/questions/11568855/why-cant-eclipse-resolve-class-in-same-package This worked. – ItsMeGokul Jan 10 '18 at 16:16
  • @ItsMeGokul I doubt that this is your problem. Your problem is that your program is syntactically wrong, e.g. `B.fun1();` must be placed within a method, not within a class. – Turing85 Jan 10 '18 at 16:20

0 Answers0