# data[].attributes.body
Coding for triangle

class Shape {

// Common properties and methods for all shapes

protected double area;

public double getArea() {

return area;

}

}

class Triangle extends Shape {

private double base;

private double height;

public Triangle(double base, double height) {

this.base = base;

this.height = height;

calculateArea();

}

private void calculateArea() {

area = 0.5 base height;

}

}

public class TriangleDemo {

public static void main(String[] args) {

Triangle triangle = new Triangle(5.0, 8.0);

System.out.println("Triangle Area: " + triangle.getArea());

}

}

# data[].attributes.body
// Superclass

class Shape {

double area;

// Method to calculate area (will be overridden by subclasses)

void calculateArea() {

// This is a placeholder method that will be overridden by subclasses

}

}

// Subclass (inherits from Shape)

class Triangle extends Shape {

double base;

double height;

// Constructor for Triangle

Triangle(double base, double height) {

this.base = base;

this.height = height;

}

// Override the method to calculate area for a triangle

void calculateArea() {

area = 0.5 base height;

}

}

class TriangleDemo {

public static void main(String args[]) {

Triangle obj1 = new Triangle(10, 5);

obj1.calculateArea();

System.out.println("Area of the triangle: " + obj1.area);

}

}

# data[].attributes.body
Coding for area of triangle

// Superclass

class Shape {

double area;

// Method to calculate area (will be overridden by subclasses)

void calculateArea() {

// This is a placeholder method that will be overridden by subclasses

}

}

// Subclass (inherits from Shape)

class Triangle extends Shape {

double base;

double height;

// Constructor for Triangle

Triangle(double base, double height) {

this.base = base;

this.height = height;

}

// Override the method to calculate area for a triangle

void calculateArea() {

area = 0.5 base height;

}

}

class TriangleDemo {

public static void main(String args[]) {

Triangle obj1 = new Triangle(10, 5);

obj1.calculateArea();

System.out.println("Area of the triangle: " + obj1.area);

}

}

# data[].attributes.body
// Superclass

class Shape {

double area;

// Method to calculate area (will be overridden by subclasses)

void calculateArea() {

// This is a placeholder method that will be overridden by subclasses

}

}

// Subclass (inherits from Shape)

class Triangle extends Shape {

double base;

double height;

// Constructor for Triangle

Triangle(double base, double height) {

this.base = base;

this.height = height;

}

// Override the method to calculate area for a triangle

void calculateArea() {

area = 0.5 base height;

}

}

class TriangleDemo {

public static void main(String args[]) {

Triangle obj1 = new Triangle(10, 5);

obj1.calculateArea();

System.out.println("Area of the triangle: " + obj1.area);

}

}

# data[].attributes.body
// This is the superclass representing geometric shapes

class Shape {

double area;

// This method is a placeholder for calculating the area and will be overridden by subclasses

void calculateArea() {

// This method will be replaced by specific implementations in subclasses

}

}

// This is a subclass of Shape, representing a triangle

class Triangle extends Shape {

double base;

double height;

// Constructor for creating a Triangle object with given base and height

Triangle(double base, double height) {

this.base = base;

this.height = height;

}

// Override the calculateArea method to calculate the area of a triangle

void calculateArea() {

area = 0.5 base height;

}

}

// This class demonstrates the use of the Triangle class

class TriangleDemo {

public static void main(String args[]) {

// Create a Triangle object with a base of 10 and a height of 5

Triangle obj1 = new Triangle(10, 5);

// Calculate the area of the triangle

obj1.calculateArea();

// Display the calculated area of the triangle

System.out.println("Area of the triangle: " + obj1.area);

}

}

# data[].attributes.body
Area Of Triangle

// super class

class areaTriangle {

public double calculateArea() {

return 0.0;

}

}

// sub-class

class Triangle extends areaTriangle {

double base;

double height;

public Triangle(double base, double height) {

this.base = base;

this.height = height;

}

public double calculateArea() {

return 0.5 base height;

}

}

class TrangleDemo {

public static void main(String[] args) {

// Create a Triangle object

Triangle triangle = new Triangle(25, 20);

// Calculate and print the area of the triangle

double area = triangle.calculateArea();

System.out.println("Area of the triangle: " + area);

}

}

# data[].attributes.body
// Superclass

class Shape {

double area;

// Method to calculate area (will be overridden by subclasses)

void calculateArea() {

// This is a placeholder method that will be overridden by subclasses

}

}

// Subclass (inherits from Shape)

class Triangle extends Shape {

double base;

double height;

// Constructor for Triangle

Triangle(double base, double height) {

this.base = base;

this.height = height;

}

// Override the method to calculate area for a triangle

void calculateArea() {

area = 0.5 base height;

}

}

class TriangleDemo {

public static void main(String args[]) {

Triangle obj1 = new Triangle(10, 5);

obj1.calculateArea();

System.out.println("Area of the triangle: " + obj1.area);

}

}

# data[].attributes.body
b)class Shape {

public double getArea() {

return 0; // Default implementation, to be overridden by subclasses

}

}

class Triangle extends Shape {

private double base;

private double height;

public Triangle(double base, double height) {

this.base = base;

this.height = height;

}

@Override

public double getArea() {

return 0.5 base height; // Calculate the area of the triangle

}

}

public class TriangleDemo {

public static void main(String[] args) {

Triangle triangle = new Triangle(5.0, 8.0); // Example values for base and height

double area = triangle.getArea();

System.out.println("Triangle Area: " + area);

}

}

# data[].attributes.body
b)class Shape {

public double getArea() {

return 0; // Default implementation, to be overridden by subclasses

}

}

class Triangle extends Shape {

private double base;

private double height;

public Triangle(double base, double height) {

this.base = base;

this.height = height;

}

@Override

public double getArea() {

return 0.5 base height; // Calculate the area of the triangle

}

}

public class TriangleDemo {

public static void main(String[] args) {

Triangle triangle = new Triangle(5.0, 8.0); // Example values for base and height

double area = triangle.getArea();

System.out.println("Triangle Area: " + area);

}

}

# data[].attributes.body
b)class Shape {

public double getArea() {

return 0; // Default implementation, to be overridden by subclasses

}

}

class Triangle extends Shape {

private double base;

private double height;

public Triangle(double base, double height) {

this.base = base;

this.height = height;

}

@Override

public double getArea() {

return 0.5 base height; // Calculate the area of the triangle

}

}

public class TriangleDemo {

public static void main(String[] args) {

Triangle triangle = new Triangle(5.0, 8.0); // Example values for base and height

double area = triangle.getArea();

System.out.println("Triangle Area: " + area);

}

}

# data[].attributes.body
// Superclass

class Shape {

double area;

// Method to calculate area (will be overridden by subclasses)

void calculateArea() {

// This is a placeholder method that will be overridden by subclasses

}

}

// Subclass (inherits from Shape)

class Triangle extends Shape {

double base;

double height;

// Constructor for Triangle

Triangle(double base, double height) {

this.base = base;

this.height = height;

}

// Override the method to calculate area for a triangle

void calculateArea() {

area = 0.5 base height;

}

}

class TriangleDemo {

public static void main(String args[]) {

Triangle obj1 = new Triangle(10, 5);

obj1.calculateArea();

System.out.println("Area of the triangle: " + obj1.area);

}

}

# data[].attributes.body
// Superclass

class Shape {

double area;

// Method to calculate area (will be overridden by subclasses)

void calculateArea() {

// This is a placeholder method that will be overridden by subclasses

}

}

// Subclass (inherits from Shape)

class Triangle extends Shape {

double base;

double height;

// Constructor for Triangle

Triangle(double base, double height) {

this.base = base;

this.height = height;

}

// Override the method to calculate area for a triangle

void calculateArea() {

area = 0.5 base height;

}

}

class TriangleDemo {

public static void main(String args[]) {

Triangle obj1 = new Triangle(10, 5);

obj1.calculateArea();

System.out.println("Area of the triangle: " + obj1.area);

}

}

# data[].attributes.body
AREA OF TRIANGLE

abstract class areaTriangle {

public abstract double calculateArea();

}

class Triangle extends areaTriangle {

private double base;

private double height;

public Triangle(double base, double height) {

this.base = base;

this.height = height;

}

public double calculateArea() {

return 0.5 base height;

}

}

class TriangleDemo {

public static void main(String[] args) {

Triangle triangle = new Triangle(25, 20);

double area = triangle.calculateArea();

System.out.println("Area of the triangle: " + area);

}

}

# data[].attributes.body
class Shape {

// Common properties and methods for all shapes

protected double area;

public double getArea() {

return area;

}

}

class Triangle extends Shape {

private double base;

private double height;

public Triangle(double base, double height) {

this.base = base;

this.height = height;

calculateArea();

}

private void calculateArea() {

area = 0.5 base height;

}

}

public class TriangleDemo {

public static void main(String[] args) {

Triangle triangle = new Triangle(5.0, 8.0);

System.out.println("Triangle Area: " + triangle.getArea());

}

}

# data[].attributes.body
Area Of Triangle

// super class

class areaTriangle {

public double calculateArea() {

return 0.0;

}

}

// sub-class

class Triangle extends areaTriangle {

double base;

double height;

public Triangle(double base, double height) {

this.base = base;

this.height = height;

}

public double calculateArea() {

return 0.5 base height;

}

}

class TrangleDemo {

public static void main(String[] args) {

// Create a Triangle object

Triangle triangle = new Triangle(25, 20);

// Calculate and print the area of the triangle

double area = triangle.calculateArea();

System.out.println("Area of the triangle: " + area);

}

}

# data[].attributes.body
// Superclass

class Shape {

double area;

// Method to calculate area (will be overridden by subclasses)

void calculateArea() {

// This is a placeholder method that will be overridden by subclasses

}

}

// Subclass (inherits from Shape)

class Triangle extends Shape {

double base;

double height;

// Constructor for Triangle

Triangle(double base, double height) {

this.base = base;

this.height = height;

}

// Override the method to calculate area for a triangle

void calculateArea() {

area = 0.5 base height;

}

}

class TriangleDemo {

public static void main(String args[]) {

Triangle obj1 = new Triangle(10, 5);

obj1.calculateArea();

System.out.println("Area of the triangle: " + obj1.area);

}

}

# data[].attributes.body
Area of Triangle

class Triangle {

float height;

float base;

}

class Area extends Triangle {

float area;

// Method to calculate area of the triangle

void calculateArea() {

area = height base 0.5;

}

}

public class Main {

public static void main(String[] args) {

// Creating an object of the Area class

Area triangleArea = new Area();

// Setting height and base values

triangleArea.height = 5;

triangleArea.base = 10;

// Calculating the area

triangleArea.calculateArea();

// Printing the calculated area

System.out.println("Area of the triangle: " + triangleArea.area);

}

}

# data[].attributes.body
1. Sample 4 output:

Name = Sultana

Age = 17

Mark 1 = 67

Mark 2 = 87

mark 3 = 97

2. Area of triangle inheritance program:

//superclass
class Shape {
	double area;
}

//subclass
class Triangle extends Shape {
	double base;
	double height;

	//constructor
	public Triangle(double base, double height) {
		this.base = base;
		this.height = height;
	}

	void calcArea() {
		area = 0.5 * base * height;
}
}

public class AreaTriangle {
	public static void main (String[] args) {
		double base = 5;
		double height = 12;

		Triangle triangle = new Triangle(base, height);

		triangle.calcArea(); //call calcArea method to calculate area

		System.out.println("Area of triangle: " + triangle.area);
	}
}

# data[].attributes.body
AREA OF TRIANGLE

//superclass

class Shape {

double area;

}

//subclass

class Triangle extends Shape {

double width;

double height;

//constructor

public Triangle(double width, double height) {

this.width = width;

this.height = height;

}

void calcArea() {

area = 0.5 width height;

}

}

class AreaTriangle {

public static void main (String[] args) {

double width = 7;

double height = 14;

Triangle triangle = new Triangle(width, height);

triangle.calcArea(); //call calcArea method to calculate area

System.out.println("Area of triangle: " + triangle.area);

}

}

# data[].attributes.body
a) Output Sample 4

Name = Sultana

Age = 17

Mark 1 = 67

Mark 2 = 87

Mark 3 = 97

b) Area of triangle

//superclass

class Shape{

double area;

}

//subclass

class Triangle extends Shape{

double base;

double height;

//constructor

public Triangle(double base,double height)

{

this.base=base;

this.height=height;

}

void calcArea(){

area = 0.5*base*height:

}

}

public class AreaTriangle{

public static void main(String[] args)

{

double base=5;

double height=13;

Triangle triangle=new Triangle(base,height);

triangle.calcArea();

System.out.println("Area of the Triangle:" + triangle.area);

}

}

# data[].attributes.body
1) Output

Name = Sultana

Age = 17

Mark1 = 67

Mark2 = 87

Mark3 = 97

2) Area of triangle

class Shape {

}

class Triangle extends Shape {

double base;

double height;

public Triangle(double base, double height) {

this.base = base;

this.height = height;

}

public double calculateArea() {

return 0.5 base height;

}

}

public class Main {

public static void main(String[] args) {

Triangle triangle = new Triangle(5.0, 8.0);

System.out.println("Area of the triangle: " + triangle.calculateArea());

}

}

# data[].attributes.body
class Person {

String name;

int age;

}

class Student extends Person //sub class

{

int mark1,mark2,mark3;

void DisplayData()

{

System.out.println("Name = "+name);

System.out.println("Age=" +age);

System.out.println("Mark1="+mark1);

System.out.println("Mark2=" +mark2);

System.out.println("Mark3="+mark3);

}

}

class StudentDemo{

public static void main(String args[]){

Student obj1 =new Student();

obj1.name="Sultana";

obj1.age=17;

obj1.mark1=67;

obj1.mark2=87;

obj1.mark3=97;

obj1.DisplayData();

}

}

output =

Name=sultana

Age=17

Mark1=67

Mark2=87

Mark3=97

process completed

# data[].attributes.body
abstract class areaTriangle {

public abstract double

calculateArea();

}

class Triangle extends

areaTriangle {

private double base;

private double height;

public Triangle (double base,

double height) {

this.base = base;

this.height = height;

}

public double calculateArea(){

return 0.5 base height;

}

}

class TriangleDemo {

public static void main(String[]

args){

Triangle triangle = new

Triangle(25, 20);

double area =

triangle.calculateArea();

System.out.println( "Area of the triangle: " + area);

}

}

# data[].attributes.body
a) Output Sample 4

Name = Sultana

Age = 17

Mark 1 = 67

Mark 2 = 87

Mark 3 = 97

b) Area of triangle

//Superclass

class Shape

{

double area;

}

//Subclass

class Triangle extends Shape

{

double base;

double height;

//constructor

public Triangle(double base, double height)

{

this.base=base;

this.height=height;

}

void calcArea()

{

Area = 0.5*base*height;

}

}

public class AreaTriangle

{

public static void main(String[] args)

{

double base=6;

double height=12;

Triangle triangle=new Triangle(base, height);

triangle.calcArea();

System.out.println("Area of the Triangle:" + Area);

}

}