Assignment 4
Assignment 4
Bhoomi agarwal
2200290100054
Question 1
}
void getPerimeter()
{
System.out.println("Perimeter is "+ (2*3.14*radius));
}
void area()
{
System.out.println("Area is "+(3.14*radius*radius));
}
}
public class Circle extends Shape
{
Circle(int a)
{
super(a);
}
public static void main(String[] args)
{
Circle t= new Circle(5);
t.getPerimeter();
t.area() ;
}
}
Question 2
public class BankAccount {
int bal;
BankAccount(int a)
{
bal=a;
}
void deposit(int k)
{
bal+=k;
}
void withdraw(int k)
{ if(bal>=100)
{ bal-=k;
}
else
{ System.out.println("withdraw can not be done");
}
}
}
Question 3
public class X {
int i,j;
X(int i,int j)
{
this.i=i;
this.j=j;
}
void disp()
{
System.out.println("value of i "+i+"\nvalue of j is "+j);
}
}
public class Y extends X{
int i,j;
Y(int i,int j, int a,int b)
{
super(i,j);
this.i=a;
this.j=b;
}
void disp()
{
super.disp();
System.out.println("\nY's class ");
System.out.println("value of i "+this.i+"\nvalue of j is
"+this.j);
}
}
public class UsingSuperDemo {
}
Question 4
package test2;
public class X {
int i,j;
X(int a,int b)
{
i=a;
j=b;
}
void sum()
{
System.out.println("Sum is "+(i+j));
}
}
package test2;