JAVA Lab 7
JAVA Lab 7
Am.sc.u4aie24029
Code :
class Shape {
private String color;
public Shape() {
this.color = "undefined";
}
public Circle() {
super();
}
public Circle(double radius) {
super();
this.radius = radius;
}
Output :
2 Make data members protected in shape and
circle classes and try to access it in sub
class.
Code :
class Shape {
protected String color;
public Shape() {
this.color = "undefined";
}
public Circle() {
super();
}
Output :
3
Code :
public Point() {
this.x = 0;
this.y = 0;
}
System.out.println(line
System.out.println("Length: " + line1.getLength());
System.out.println(line2);
System.out.println("Length: " + line2.getLength());
}
}
4
package gshapes;
package gshapes;
public Circle() {}
package gshapes;
public class Rectangle extends Shape {
protected double width = 1.0;
protected double length = 1.0;
public Rectangle() {}
package gshapes;
public class Square extends Rectangle {
public Square() {}