Java object-oriented basic code

#javaObject Oriented Basics

##Simple object-oriented
import java.util.Scanner;

public class Circle { static double r; // radius of circle static double PI=3.1415926;// pi // parameter construction method public Circle(double R){ r = R; } // no parameter construction method public Circle(){ this®; // call the parameterized construction method and initialize the radius to 2 } // method (calculate area) double area(){ return r r PI; } //overload method public double area(double r) { return r r PI; } //Static method public static double area2(double r) { return r r PI; } // Define an object of the Circle class, and output the area of ​​the circle through the object member method public static void main(String args[]) {
























Scanner input=new Scanner(System.in);
System.out.println("Please enter the radius of a circle:");
double m=input.nextInt();
Circle c = new Circle();
cr=m;
System .out.println("The area of ​​the circle calculated with the method area() is:"+c.area());
System.out.println("The area of ​​the circle calculated with the method area(double r) is:"+ c.area(m));
input.close();
}
}

Guess you like

Origin blog.csdn.net/qq_45750230/article/details/104844556