Java Programming Exercise: Polygon Structure Explained

Published: 19 February 2026
on channel: NET SAMBATH Rean IT
2
1

*This's file Class Polygon (Main Class)
package inheritanceDemo;

import java.util.Scanner;

//import javax.swing.plaf.synth.SynthOptionPaneUI;

public class Polygon {
Scanner scan = new Scanner(System.in);
double width, height;
void showWidth (double w) {

}
void showHeight(double h) {

}
}
class Rectangle extends Polygon{
void rectInput() {
System.out.print("Input rect width :");
width = scan.nextDouble();
System.out.print("Input rect hieght :");
height = scan.nextDouble();
}

void rectShow() {
System.out.print("\nRect info : \n");
System.out.println("Rect width is : " + width + " metres");
System.out.println("Rect height is : " + height + " metres");
}
}
class Triangle extends Polygon {
void triInput() {
System.out.print("Input tri width :");
width = scan.nextDouble();
System.out.print("Input tri hieght :");
height = scan.nextDouble();
}
void triShow() {
System.out.print("\nTri info : \n");
System.out.println("Tri info width is :" + width + " metres");
System.out.println("Tri height is : " + height + " metres");
}
}

*This's file Class PolygonsDemo (sub class)
package inheritanceDemo;

public class PolygonsDemo {

public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle rect = new Rectangle();
Triangle tri = new Triangle(); // can tri by class file Polygon
rect.rectInput();
tri.triInput();
rect.rectShow();
tri.triShow();

}

}

Thanks for support me!


On this page of the site you can watch the video online Java Programming Exercise: Polygon Structure Explained with a duration of hours minute second in good quality, which was uploaded by the user NET SAMBATH Rean IT 19 February 2026, share the link with friends and acquaintances, this video has already been watched 2 times on youtube and it was liked by 1 viewers. Enjoy your viewing!