package shapes;
public class Shape {
public String color;
public Shape(String color) {
System.out.println("Inside Shape constructor");
this.color = color;
}
}
public class Rectangle extends Shape {
public int height;
public int width;
public Rectangle(String color) {
super(color);
System.out.println("Inside Rectangle constructor with one argument");
}
public Rectangle(String name, int width, int height) {
this(name);
this.width = width;
this.height = height;
System.out.println("Inside Rectangle constructor with three arguments");
}
public static void main(String[] args) {
Rectangle r = new Rectangle("red", 10, 20);
System.out.println(r.color);
System.out.println(r.width);
System.out.println(r.height);
}
}
Shape.java
Rectangle.java
package shapes;
public class Shape {
public String color;
public Shape(String color) {
System.out.println("Inside Shape constructor");
this.color = color;
}
}
public class Rectangle extends Shape {
public int height;
public int width;
public Rectangle(String color) {
super(color);
System.out.println("Inside Rectangle constructor with one argument");
}
public Rectangle(String color, int width, int height) {
this(color);
this.width = width;
this.height = height;
System.out.println("Inside Rectangle constructor with three arguments");
}
public static void main(String[] args) {
Rectangle r = new Rectangle("red", 10, 20);
System.out.println(r.color);
System.out.println(r.width);
System.out.println(r.height);
}
}
Shape.java
Rectangle.java
package shapes;
public class Shape {
public String color;
public Shape(String color) {
System.out.println("Inside Shape constructor");
this.color = color;
}
}
public class Rectangle extends Shape {
public int height;
public int width;
public Rectangle(String color) {
super(color);
System.out.println("Inside Rectangle constructor with one argument");
}
public Rectangle(String color, int width, int height) {
this(color);
this.width = width;
this.height = height;
System.out.println("Inside Rectangle constructor with three arguments");
}
public static void main(String[] args) {
Rectangle r = new Rectangle("red", 10, 20);
System.out.println(r.color);
System.out.println(r.width);
System.out.println(r.height);
}
}
Shape.java
Rectangle.java
public class Shape {
public String color;
public Shape(String color) {
System.out.println("Inside Shape constructor");
this.color = color;
}
}
public class Rectangle extends Shape {
public int height;
public int width;
public Rectangle(String color) {
super(color);
System.out.println("Inside Rectangle constructor with one argument");
}
public Rectangle(String color, int width, int height) {
this(color);
this.width = width;
this.height = height;
System.out.println("Inside Rectangle constructor with three arguments");
}
public static void main(String[] args) {
Rectangle r = new Rectangle("red", 10, 20);
System.out.println(r.color);
System.out.println(r.width);
System.out.println(r.height);
}
}
Shape.java
Rectangle.java
public class Shape {
public String color;
public Shape(String color) {
System.out.println("Inside Shape constructor");
this.color = color;
}
}
public class Rectangle extends Shape {
public int height;
public int width;
public Rectangle(String color) {
super(color);
System.out.println("Inside Rectangle constructor with one argument");
}
public Rectangle(String color, int width, int height) {
this(color);
this.width = width;
this.height = height;
System.out.println("Inside Rectangle constructor with three arguments");
}
public static void main(String[] args) {
Rectangle r = new Rectangle("red", 10, 20);
System.out.println(r.color);
System.out.println(r.width);
System.out.println(r.height);
}
}
Shape.java
Rectangle.java
public class Circle {
private static final double pi = 3.14159;
private int x, y;
private int r;
// Only 1 variable for all Circle objects
public static int numberOfCircles = 0;
public Circle() {
numberOfCircles++;
}
public double circumference() {
return 2 * pi * r;
}
public static void main(String[] args) {
System.out.println("Number of circles: " + Circle.numberOfCircles); // 0
Circle c1 = new Circle();
System.out.println("Number of circles: " + Circle.numberOfCircles); // 1
Circle c2 = new Circle();
System.out.println("Number of circles: " + Circle.numberOfCircles); // 2
}
}
public class Circle {
private static final double pi = 3.14159;
private int x, y;
private int r;
// Only 1 variable for all Circle objects
public static int numberOfCircles = 0;
public Circle() {
numberOfCircles++;
}
public double circumference() {
return 2 * pi * r;
}
public static void main(String[] args) {
System.out.println("Number of circles: " + Circle.numberOfCircles); // 0
Circle c1 = new Circle();
System.out.println("Number of circles: " + Circle.numberOfCircles); // 1
Circle c2 = new Circle();
System.out.println("Number of circles: " + Circle.numberOfCircles); // 2
}
}
public class Circle {
private static final double pi = 3.14159;
private int x, y;
private int r;
// Only 1 variable for all Circle objects
public static int numberOfCircles = 0;
public Circle() {
numberOfCircles++;
}
public double circumference() {
return 2 * pi * r;
}
public static void main(String[] args) {
System.out.println("Number of circles: " + Circle.numberOfCircles); // 0
Circle c1 = new Circle();
System.out.println("Number of circles: " + Circle.numberOfCircles); // 1
Circle c2 = new Circle();
System.out.println("Number of circles: " + Circle.numberOfCircles); // 2
}
}
/**
* File class that stores content under a file name
*/
public class File {
/**
* Constructor used to create a file
* @param fileName the name of the file
* @param content contents of the file
*/
public File(String fileName, String content) {}
/**
* Constructor used to make a partial file when receiving a new file
* I.e., content.length() != fileSize with no compression
* @param fileName
* @param fileSize
*/
protected File(String fileName, int fileSize) {}
/**
* Checks if transfer has been completed
* @return true if it has been completed
*/
public boolean hasTransferBeenCompleted() {}
}
VSCode Extensions
public class Circle {
int a; // Default
private int b; // Private
protected int c; // Protected
public int d; // Public
}