Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

No enclosing instance of type Foo is accessible. Must qualify the allocation with an enclosing instance of type Foo (e.g. x.new A() where x is an instance of Foo

static class SimpleCircle
Comment

No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing instance of type Main (e.g. x.new A() where x is an instance of Main).

public class TestSimpleCircle {

    class SimpleCircle {
        double radius;

        SimpleCircle(){
            radius = 1;
        }

        SimpleCircle(double newRadius){
            radius = newRadius;
        }

        double getArea() {
            return radius * radius * Math.PI;
        }

        double getPerimeter() {
            return 2 * radius * Math.PI;
        }

        void setRadius(double newRadius) {
            radius = newRadius;
        }
    }

    public static void main(String [] args) {
        SimpleCircle circle = new SimpleCircle();
        System.out.println("the area of the circle of radius "+circle.radius+" is "+circle.getArea());

        SimpleCircle circle2 = new SimpleCircle(25);
        System.out.println("the area of the circle of radius "+circle2.radius+" is "+circle2.getArea());

        SimpleCircle circle3 = new SimpleCircle(125);
        System.out.println("the area of the circle of radius "+circle3.radius+" is "+circle3.getArea());

        circle.radius = 100;
        System.out.println("The area of the circle of radius "+circle.radius+" is "+circle.getArea());
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to remove an element from an arraylist java 
Java :: method overriding in java 
Java :: object in java 
Java :: Java forEach() Method 
Java :: java map sorted by key 
Java :: java array 
Java :: java thread 
Java :: super class java 
Java :: string comparison using == in java 
Java :: kafkalistener annotation pass topic from properties file 
Java :: Service vs IntentService. 
Java :: fragment to activity typecasting 
Java :: Java public no-arg constructor 
Java :: preset arraylist java 
Java :: foreach() java 
Java :: android pick up photo from local device 
Java :: square oot of 154 
Java :: url to json 
Java :: spring secutiry urls redirecting 
Java :: thread dump 
Java :: pack in swing 
Java :: calculate tip and sales tax function 
Java :: java package keyword 
Java :: java function that returns the index of the largest value in an array 
Java :: Method returns value 
Java :: Java Using allOf(Size) 
Java :: java konsoleneingabe 
Java :: java random 8 digit number 
Java :: Java Throwing checked exception 
Java :: ldap java connection 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =