Jump to content
  • Advertisement
Sign in to follow this  
Carbon101

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!