Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,942 questions

51,880 answers

573 users

How to use this to invoke a constructor in Java

1 Answer

0 votes
public class Circle {
    double radius;
    public Circle() {
        this(10);
        System.out.println("public Circle()");
    }
    Circle(double radius) {
        System.out.println("Circle(double radius)");
        this.radius = radius;
    }
    double Area() {
        return Math.PI * this.radius * this.radius ;    
    }
    double Perimeter() {
        return 2 * Math.PI * this.radius;
    }
    void set_radius(double radius) {
        this.radius = radius;
    }
    public static void main(String args[]) {
        Circle circle1 = new Circle();
        System.out.println(circle1.Area());
        System.out.println(circle1.Perimeter());
    }
}
 
 
/*
run:
 
Circle(double radius)
314.1592653589793
62.83185307179586
 
*/

 



answered Jul 25, 2019 by avibootz

Related questions

1 answer 134 views
1 answer 153 views
1 answer 149 views
1 answer 113 views
113 views asked Dec 12, 2020 by avibootz
1 answer 157 views
157 views asked Jul 25, 2019 by avibootz
2 answers 173 views
173 views asked Jul 5, 2017 by avibootz
...