chaekayeon
Grasshopper
Meron po bang nakakaalam po nito?
import java.util.Scanner;
class Quadrilateral {
public void showDescription() {
System.out.println("- is quadrilateral");
}
}
class Rectangle extends Quadrilateral {
public void showDescription() {
System.out.println("- has 4 right angles");
super.showDescription();
}
}
class Square extends Rectangle {
public void showDescription() {
System.out.println("- has 4 equal sides");
super.showDescription();
}
}
class RunQuad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Press R for Rectangle or S for Square.");
String userInput = sc.nextLine();
Quadrilateral newRec = new Rectangle();
Rectangle newSqua = new Square();
if(userInput.equalsIgnoreCase("R")){
System.out.println("A Rectangle:");
newRec.showDescription();
}
else if(userInput.equalsIgnoreCase("S")){
System.out.println("A Square:");
newSqua.showDescription();
}
}
}