Java File
Java File
WAP to create a simple class to find out the area and perimeter of rectangle and
box using super and this keyword.
import java.util.*;
class Use_Rectangle {
Q2. WAP to design a class account using the inheritance and static that show
all function of bank (withdrawal, deposit).
class account {
// withdrawal
int withdrawal)
+ withdrawal);
+ total);
each withdrawal.*/
try {
Thread.sleep(1000);
catch (InterruptedException e) {
e.printStackTrace();
else {
System.out.println(name
+ withdrawal);
try {
Thread.sleep(1000);
catch (InterruptedException e) {
// occurred
e.printStackTrace();
int deposit)
+ total);
try {
Thread.sleep(1000);
// exception
catch (InterruptedException e) {
e.printStackTrace();
// Method - Withdraw
String name;
int rupee;
this.object = ob;
this.name = name;
this.rupee = money;
// Class 2
Bank object;
String name;
int rupee;
this.object = ob;
this.name = name;
this.rupee = money;
}
public void run() { object.deposit(name, rupee); }
// Class 3
// Main class
class GFG {
// Creating threads
ThreadWithdrawal t1
ThreadWithdrawal t2
ThreadDeposit t3
ThreadWithdrawal t4
ThreadWithdrawal t5
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
output
System.out.println("SportsBike Brake");
System.out.println("MountainBike Brake");
class Main {
m1.brake();
s1.brake();
output
Q4. WAP to handle the exception using try and multiple catch block.
import java.util.Scanner;
try
int n = Integer.parseInt(scn.nextLine());
if (98%n == 0)
}
catch (NumberFormatException | ArithmeticException ex)
output
// main method
// main try-block
try {
// try-block2
try {
// try-block3
try {
int arr[] = { 1, 2, 3, 4 };
System.out.println(arr[10]);
catch (ArithmeticException e) {
System.out.println("Arithmetic exception");
System.out.println(" try-block1");
}
// handles ArithmeticException if any
catch (ArithmeticException e) {
System.out.println("Arithmetic exception");
System.out.println(" try-block2");
System.out.print("ArrayIndexOutOfBoundsException");
System.out.print("Exception");
output
// Main class
// TestEvenOddByCheckingLSB
// Method 1
{
if (a != 0) {
if (Integer.toBinaryString(a).endsWith("0")) {
return "Even";
else {
return "Odd";
else {
return "Zero";
// Method 2
System.out.println(
Output
Q.7 WAP to show string reverse
import java.lang.*;
import java.io.*;
import java.util.*;
// Class of ReverseString
class ReverseString {
// into bytes[].
// result byte[]
System.out.println(new String(result));
}
Output
import java.util.*;
class matrix {
System.out.println(Arrays.toString(row));
throws IOException
int mat[][] = { { 6, 7, 9, 4 },
{ 5, 6, 5, 8 },
{ 9, 15, 11, 19 } };
output
Q.9 WAP for factorial of a number
class Factorial {
int factorial(int n)
// Driver Code
int num = 6;
Output
class B extends A {
class C extends A {
class D extends A {
public void print_D() { System.out.println("Class D"); }
// Driver Class
obj_B.print_A();
obj_B.print_B();
obj_C.print_A();
obj_C.print_C();
obj_D.print_A();
obj_D.print_D();
Output