Constructors
public class Person { String name; int age; public Person() { name = "Unknown"; age = 0; } }public class Book { String title; String author; public Book(String title, String author) { this.title = title; this.author = author; } }public class Rectangle { int length; int width; public Rectangle(int length, int width) { this.length = length; this.width = width; } public Rectangle() { this(0, 0); // Call the parameterized constructor with default values } }public class Circle { double radius; public Circle(double radius) { this.radius = radius; } }public class Circle { double radius; public Circle(double radius) { this.radius = radius; } public Circle(int radius) { this.radius = (double) radius; } public Circle(float radius) { this.radius = (double) radius; } }public class MathConstants { public static final double PI; public static final double E; static { PI = 3.14159; E = 2.71828; } }public class Dog { String name; String breed; { name = "Unknown"; breed = "Unknown"; } }public class Car { String make; String model; int year; public Car(Car otherCar) { this.make = otherCar.make; this.model = otherCar.model; this.year = otherCar.year; } }public class ImmutablePoint { final int x; final int y; public ImmutablePoint(int x, int y) { this.x = x; this.y = y; } }public class CircleCalculator { private final Circle circle; public CircleCalculator(Circle circle) { this.circle = circle; } }
Last updated