0% found this document useful (0 votes)
2 views

Assignment 4

The document contains Java code for various object-oriented programming assignments, focusing on class inheritance and method overriding. It includes implementations for shapes like circles, bank accounts, and a hierarchy of classes demonstrating the use of constructors and method calls. Each section provides a main method to execute the code and display results related to the respective classes.

Uploaded by

Bhoomi Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 4

The document contains Java code for various object-oriented programming assignments, focusing on class inheritance and method overriding. It includes implementations for shapes like circles, bank accounts, and a hierarchy of classes demonstrating the use of constructors and method calls. Each section provides a main method to execute the code and display results related to the respective classes.

Uploaded by

Bhoomi Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

OOPS ASSIGNMENT 4(LAB)

Bhoomi agarwal
2200290100054

Question 1

public class Shape {


int radius;
Shape(int a)
{ radius=a;

}
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");
}
}

public class SavingAccount extends BankAccount{


SavingAccount(int k)
{
super(k);
}
public static void main(String[] args) {
SavingAccount m=new SavingAccount(10000);
System.out.println("current balance is "+m.bal);
m.deposit(10000);
System.out.println("balance after deposit is "+m.bal);
m.withdraw(100);
System.out.println("balance after withdraw is "+m.bal);
}

}
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 {

public static void main(String[] args) {


Y n=new Y(1,2,3,4);
n.disp();
}

}
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;

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 diff()
{
System.out.println("difference is "+(i-j));
}
}
package test2;

public class Z extends Y {


int i,j;
Z(int a,int b,int c, int d,int e,int f)
{
super(a,b,c,d);
this.i=e;
this.j=f;
}
void product()
{
System.out.println("Product is "+(i*j));
}
public static void main(String[] args) {
Z q=new Z(10,9,8,7,6,5);
q.sum();
q.diff();
q.product();
}

You might also like