• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variables access

 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have one java class Base in d:\trinadh
Base.java

public class Base {
public int iNoEnc=77;
}
i have another class in d:\trinadh
sub.java
public class sub{
public static void main(String argv[]){
Base b = new Base();
b.iNoEnc=2;
System.out.println(b.iNoEnc);
}//End of main
}
iam trying to acess the variable defined in base.java in sub.java

but it is giving error at Base
what is the problem
i have set the classpath as d:\trinadh
tell me how to resolve this problem
 
Dave Jones
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please post the error message you get, it might shed some light on the problem
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above code should not give any error. Can you please post the exact error.
 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NoEnc.java:2: cannot resolve symbol
symbol : class Base
location: class sub
public class sub extends Base{
^
NoEnc.java:4: cannot resolve symbol
symbol : class Base
location: class sub Base b = new Base();
^
NoEnc.java:4: cannot resolve symbol
symbol : class Base
location: class sub Base b = new Base();


these are the errors i have got
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you make any changes to your base and sub java files?
If yes, check if you have saved it and compile it again.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you have noEnc.class, Base.class & , sub.class files
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15278
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You gave us the source code for the classes Base and sub, but the errors happen in class NoEnc, and you didn't tell us anything about that class.

Have a good look at the compiler error messages. Those messages tell you exactly in which line of which source file an error happens.

EDIT: Oh, wait a minute. Did you save the source code of the two classes in a file named NoEnc.java? Don't do that. Instead, make two source files, Base.java and sub.java. Java source files should have the same names as the class names.

By the way, in the code you presented in your original post, sub did not extend Base, so you didn't post the code you're trying to compile.
[ December 13, 2005: Message edited by: Jesper de Jong ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic