Posts

Showing posts from December, 2019

Interface assignement

Image
Create a class Figure with two data members’ i.e dim1 and dim2. Create an abstract method that returns area and pass these data members as a parameter.  Create two classes’ rectangle and triangle inherited from Figure. Take the value of variables from the user in main function. Create one object of each and display the area of rectangle and triangle. abstract class Figure{        public static final int dim1 = 0;        public static final int dim2 = 0;     public abstract float area( int a , int b ); } class Traingle extends Figure{        @Override        public float area( int a , int b ) {               return (( a * b )/2); //Assumption        } } class Rectangle extends Figure{ ...

java assignment interface

Image
a. Write a program that declares two classes. The parent class is called Simple that has two data members a and b to store two numbers. It has four member functions:  a. The Add() function adds two numbers and displays the result. b. The Sub() function subtracts two numbers and display the result.  c. The Mul() function multiples two numbers and display the result d. The div() function is used to divide two numbers and displays the result.  The child class is called Complex that overrides all four functions. Each function Answer a: interface Simple{        public static final int a = 0;        public static final int b = 0;        public int   add( int a , int b );        public int   sub( int a , int b );        public float   div( int a , int b );   ...