Professional Documents
Culture Documents
Ajp Exp5
Ajp Exp5
Ajp Exp5
import java.util.*;
import java.io.*;
import javax.swing.*;
class Box<T> {
public T contents;
Box(T c){
contents =c;
public T what_is_inside(){
return contents;
contents =t;
class Exp5_1{
public static void main(String [] args){
b1.put_something("Weapons");
OUTPUT:
--------------------------------------------------------------------------------------------------------------------------------------
PROGRAM 2: Write a java program to demonstrate multiple type parameters in generic classes
import java.io.*;
import java.util.*;
class MyList<T> {
list.add(element);
T get(int index) {
return list.get(index);
int size() {
return list.size();
return list.contains(element);
class Exp5_2{
Fruits.add("Mango");
Fruits.add("Custard apple");
Fruits.add("Banana");
Fruits.add("Apple");
System.out.println("Total number of the fruits :"+Fruits.size());
System.out.println(Fruits.get(i));
OUTPUT:
Mango
Custard apple
Banana
Apple
--------------------------------------------------------------------------------------------------------------------------------------
import java.util.*;
import java.io.*;
A first;
B second;
C third;
Triple(A first, B second, C third) {
this.first = first;
this.second = second;
this.third = third;
A getFirst() {
return first;
B getSecond() {
return second;
C getThird() {
return third;
this.first = first;
this.second = second;
this.third = third;
String tostring() {
return "(" + first + ", " + second + ", " + third + ")";
myTriple.setFirst("God Boy");
myTriple.setSecond(77);
myTriple.setThird(false);
OUTPUT:
myTriple = Triple@452b3a41
--------------------------------------------------------------------------------------------------------------------------------------
import java.util.*;
import java.io.*;
String name;
int age;
T treatment;
this.name = name;
this.age = age;
this.treatment = treatment;
String getName() {
return name;
int getAge() {
return age;
T getTreatment() {
return treatment;
}
void setTreatment(T treatment) {
this.treatment = treatment;
int roomNumber;
this.roomNumber = roomNumber;
int getRoomNumber() {
return roomNumber;
@Override
void printPatientInfo() {
System.out.println("Name: " + getName() + ", Age: " + getAge() + ", Treatment: " +
getTreatment() + ", Room Number: " + getRoomNumber());
String appointmentTime;
this.appointmentTime = appointmentTime;
String getAppointmentTime() {
return appointmentTime;
void printPatientInfo() {
System.out.println("Name: " + getName() + ", Age: " + getAge() + ", Treatment: " +
getTreatment() + ", Appointment Time: " + getAppointmentTime());
class Exp5_4{
l1.printPatientInfo();
o1.printPatientInfo();
OUTPUT:
D:\Js-projects\Advanced java>java Exp5_4
--------------------------------------------------------------------------------------------------------------------------------------