# Nested Class not working properly

This topic is 2069 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Can somebody help me figure out the problem in the following code sample. My IDE says I have a mistake but I can't detect it. I am having trouble with the Inner Class.

I am using eclipse if it helps.



public class Outer {

int nums[];

Outer(int n[])

{

nums = n;

}

void Analyze()

{

Inner inOb = new Inner();

System.out.println("Minimum: " + inOb.min());

System.out.println("Maximum: " + inOb.min());

System.out.println("Average: " + inOb.min());

}

class Inner()

{

int min()

{

int m = nums[0];

for(int i = 1; i < nums.length; i++)

if(nums[i]<m)

m = nums[i];

return m;

}

int max()

{

int m = nums[0];

for(int i = 1; i < nums.length; i++)

if(nums[i] > m)

m = nums[i];

return m;

}

int avg()

{

int a = 0;

for(int i = 0; i < nums.length; i++)

a += nums[i];

return a / nums.length;

}

}

}


##### Share on other sites

I didn't think you nested classes. I thought you used something like extend.

##### Share on other sites

class Inner() {

}

you need this:

class Inner {

}


##### Share on other sites

I didn't think you nested classes. I thought you used something like extend.

Java requires only on class per file, but inside that class you can declare other classes.  Check out the Point2D.Double class from Java to see an example:

http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Point2D.Double.html

Extend is for using inheritance, which is something different.

##### Share on other sites

Thanks @Glass_Knife, I feel silly now because the error looks obvious now. Guess that's what I get for coding late Lol.

##### Share on other sites

I didn't think you nested classes. I thought you used something like extend.

Java requires only on class per file, but inside that class you can declare other classes.  Check out the Point2D.Double class from Java to see an example:

http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Point2D.Double.html

Extend is for using inheritance, which is something different.

It's been a while since I worked with Java. Guess I need a refresher project.

• 21
• 13
• 9
• 17
• 13