Define a graphic class and its subclass 22

Source: Internet
Author: User

Defines a graphic class and its subclasses (triangles and rectangular classes), calculating their area and week




Class Sanjuxing {



public double width;
public double length;
public double;
public double Perimeter;
Public double area () {
return area;
}
Public double Perimeter () {
return Perimeter;
}
}
Class Rectangle extends Sanjuxing {
Public double areagraphical () {
Area = width * length;
return area;
}
Public double Perimeter () {
Perimeter = (width + length) * 2;
return Perimeter;
}
}
Class Triangle extends Sanjuxing {
public double high;
public double Bottom;
public double side;
Public double area () {
Area = (bottom * high)/2;
return area;
}
Public double Perimeter () {
Perimeter = high + bottom + side;
return Perimeter;
}
}
public class Graphical {


public static void Main (string[] args) {
Rectangle A1 = new Rectangle ()//Declare object and create object
A1.width = 10;
A1.length = 20;
A1.areagraphical ();
A1. Perimeter ();
System.out.println ("Rectangular area:" + a1.area () + "rectangular perimeter:" + A1. Perimeter ());//Output
Triangle A2 = new triangle ()//Declare object and create object
A2.high = 5;
A2.side = 10;
A2.bottom = 6;
A2.area ();
A2. Perimeter ();
System.out.println ("Triangular area:" + a2.area () + "triangle perimeter:" + A2.) Perimeter ());//Output
}
}
}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.