GTU OOP Program - 14

14). Write a program that creates an Array List and adds a Loan object , a Date object , a string, and a Circle object to the list, and use a loop to display all elements in the list by invoking the object’s to String() method.

import java.util.ArrayList;

class Loan {
    double amount;

    Loan(double amount) {
        this.amount = amount;
    }

    public String toString() {
        return "Loan with Amount " + this.amount;
    }
}

class Date {
    public String toString() {
        return "Date: " + java.time.LocalDateTime.now();
    }
}

class Circle {
    double radius;

    Circle(double r) {
        this.radius = r;
    }

    public String toString() {
        return "circle with radius " + this.radius;
    }
}

class Program_14 {
    public static void main(String[] args) {
        ArrayList<Object> arr_list = new ArrayList<Object>();
        arr_list.add(new Loan(1000));
        arr_list.add(new Date());
        arr_list.add(new String("Kanu Thakor"));
        arr_list.add(new Circle(5));

        for (int i = 0; i < arr_list.size(); i++) {
            System.out.println((arr_list.get(i)).toString());
        }
    }
}

Output
cse gtu, gtu study material for computer engineering students gujarat
technological university oop lab manual solution

gtu oop lab manual,

oop GTU Practical,

oop Programs,

Object oriented Programming,

Gtu study material 3140705,

OOP 3140705,

oop practical list,

Java Programming,

gtu oop practical,

oop lab solution gtu

Comments

YouTube

Popular posts from this blog

GTU OOP Program - 18

GTU OS Program - 7

GTU OS Program - 3