You are on page 1of 2

Experiment 1.

Student Name: Ranjit Raj UID: 20BCS9943


Branch: CSE Section/Group: 44 B
Semester: 3rd Subject Name: Java Lab

1. Aim/Overview of the practical:

Write a program to create classes and use of different types of methods.

2. Code:

class Person {
String name;
int age;
char section;

public Person(String name, int age, char section) {


this.name = name;
this.age = age;
this.section = section;
}

public void display() {


System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("section: " + section);
}

Person modify(Person p) {
p.name = "Ranjit";
p.age = 19;
p.section = 'B';
return p;
}
}

public class Main {


public static void main(String args[]) {
Person p = new Person("Vishal", 19, 'A');
p.display();
Person p1 = p.modify(p);
p1.display();
Person p2 = p1.modify(new Person("Ranjit", 19, 'B'));
p2.display();
}
}

Output:

You might also like