Java Method Overriding: Program Implementation

By | June 11, 2017

Write a JAVA program to implement Method Overriding for following inheritance : (Assume suitable data )
Abstract Class : Shape
dim1, dim2, disp( )
abstract area ( )

Class: Rectangle
getd( ), area ( )

Class: Rectangle
getd( ), area ( )

import java.lang.*;
import java.io.*;
abstract class Shape
{
	int dim1,dim2;
	void getd()throws IOException
	{
		BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
		System.out.println ("Enter Value of 1st Dimension");
		dim1=Integer.parseInt(br.readLine());
		System.out.println ("Enter Value of 2nd Dimension");
		dim2=Integer.parseInt(br.readLine());
	}
	abstract void area();
}
class Rectangle extends Shape
{
	void getd() throws IOException
	{
		super.getd();
	}
	void area()
	{
		int a=dim1*dim2;
		System.out.println ("Area of Rectangle = "+a);
	}
}
class Triangle extends Shape
{
	void getd() throws IOException
	{
		super.getd();
	}
	void area()
	{
		double b=(1*dim1*dim2)/2;
		System.out.println ("Area of Triangle = "+b);
	}
}
class q11MethodOverriding
{
	public static void main(String args[]) throws IOException
	{
		Rectangle R = new Rectangle();
		R.getd();
		R.area();
		Triangle T = new Triangle();
		T.getd();
		T.area();
	}
}

 

Author: rabins

Rabins is CEO of R.S. Softwares Private Limited, a software and IT company in Nepal. He runs Nepal's first Internet of Things (IoT) website. He is the owner of RabinsXP who is constantly working for increasing IoT in Nepal. He also builds Android, iOS and Web Apps and crafts beautiful websites. He is also working with various social services. The main aim of Lamichhane is to digitally empower the citizens of Nepal and make the world spiritually sound better both in terms of technology and personal development. RabinsXP is the internet nickname of Rabins Sharma Lamichhane too.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.