An error is coming despite package declaration and importing what should I do?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   nitin_kale
Posted On:   Sunday, December 19, 2004 02:12 AM

There are 2 packages,having one java file.I have inherited a class from one package to another.My Super class gets compiled but not the sub class.It gives me the error package not found,what should I do? //file Question37Super.java package A; public class Question37Super { protected int i=2; } //file Question37Sub.java package B; import A.*; public class Question37Sub extends Question37Super { public static void main(String[] args){ Question37Sub q37sub = new Question37Sub(); q37sub.goFetch(); } public void goFetch(){ System.out.println("in goFetch(): i=&qu   More>>


There are 2 packages,having one java file.I have inherited a class from one package to another.My Super class gets compiled but not the sub class.It gives me the error package not found,what should I do?




//file Question37Super.java
package A;
public class Question37Super {
protected int i=2;
}




//file Question37Sub.java

package B;

import A.*;

public class Question37Sub extends Question37Super {

public static void main(String[] args){

Question37Sub q37sub = new Question37Sub();

q37sub.goFetch();

}

public void goFetch(){

System.out.println("in goFetch(): i="+i);

class GoFetchLocal{

public void goFetch(){

System.out.println("in GoFetchLocal.goFetch(): i="+i); //line 1

}

}

new GoFetchLocal().goFetch();

}
}

   <<Less

Re: An error is coming despite package declaration and importing what should I do?

Posted By:   Craig_Wood  
Posted On:   Wednesday, December 22, 2004 12:24 AM

I compiled and ran these and it worked okay.
First I put this file in folder A:



package A;

public class Q37Super {
protected int i = 2;
}


then i put this file in folder B:


package B;

import A.*;

public class Q37Sub extends Q37Super {
public static void main(String[] args) {
Q37Sub q37sub = new Q37Sub();
q37sub.goFetch();
}

public void goFetch() {
System.out.println("in goFetch(): i="+i);
class GoFetchLocal {
public void goFetch() {
System.out.println("in GoFetchLocal.goFetch(): i="+i); //line 1
}
}
new GoFetchLocal().goFetch();
}
}


Then I navigated to the B folder and did this:


C:jexpB>javac q37sub.java

C:jexpB>java B.Q37Sub
in goFetch(): i=2
in GoFetchLocal.goFetch(): i=2

About | Sitemap | Contact