The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

replay

Posted by Jose Botella on October 08, 2000 at 7:57 AM

> I'm a beginning Java programmer and am going through Bruce Eckel's "Thinking in Java" book. Here is the fairly simple code I am trying to run. The compiler is giving me the following error, "Class InnerProblem18 not found in type declaration or import." This error doesn't seem to make sense. In general, my compiler doesn't seem to "like" inner classes, as I have tried to compile some of the example source code dealing with Anonymous Inner Classes, and that chokes also. Any ideas?

> package Eckel.Chapter8.package1;

> /**
> *
> * @author PFRONTIE
> * @version
> */

> public class Problem18 extends Object {
> private double d = 10.00;
> private double multiplyDD(){
> return d*5.00;
> }
> /** Creates new Problem18 */
> public Problem18() {
> }
>
> public InnerProblem18 innerExtend() {
> return new InnerProblem18() {
> private int k = 5;
> };
> }
>
> public void callInner(){
> /*InnerProblem18 ip18 = innerExtend();
> ip18.incrementD();*/
> }
>
> public static void main(String[] args){
> Problem18 p18 = new Problem18();
> System.out.println(p18.d);
> InnerProblem18 ip18 = p18.callInner();
> System.out.println(p18.d);
> }
> }

You need a "class" keyword to define a class. So the compiler is right complaining.
It seems that you have merged several programs to do this because some memebers are
not used, but the method incrementD() is not around. Here it is an example that I
guess is near what you want...


public class Problem18 extends Object {
private double d = 10.00;
private double multiplyDD(){
return d*5.00;
}
/** Creates new Problem18 */
public Problem18() {
}

public class InnerProblem18 {
public InnerProblem18 innerExtend() {
return new InnerProblem18() ;
}
private int k = 5;
public void incrementD() { d++;}
}

public void callInner(){
InnerProblem18 ip18 = new InnerProblem18();
ip18.incrementD();
}

public static void main(String[] args){
Problem18 p18 = new Problem18();
System.out.println(p18.d);
p18.callInner();
System.out.println(p18.d);
}
}






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us