0% found this document useful (0 votes)
27 views1 page

Code2 Fixed

The document contains a Java class definition for a 'Student' with private attributes for name and age, along with methods to set and get these attributes. It also includes a 'display' method to print the student's details. The main class demonstrates creating a 'Student' object, displaying its details, updating its attributes, and displaying the updated details.

Uploaded by

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

Code2 Fixed

The document contains a Java class definition for a 'Student' with private attributes for name and age, along with methods to set and get these attributes. It also includes a 'display' method to print the student's details. The main class demonstrates creating a 'Student' object, displaying its details, updating its attributes, and displaying the updated details.

Uploaded by

Shahzaib Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

class Student{

private String name;


private int age;

public Student(String name, int age){


[Link] = name;
[Link] = age;
}
public void setAge(int age){
[Link] = age;
}
public void setName(String name){
[Link] = name;
}
public String getName(String name){
return name;
}
public int getAge(int age){
return age;
}
public void display(){
[Link]("Student Name: " +name);
[Link]("Student Age: " +age);
}
}
public class a{
public static void main(String[]args){
Student s1 = new Student("Alice", 20);
[Link]();
[Link]("Bob");
[Link](22);
[Link]("\nAfter Updating: ");
[Link]();
}
}

You might also like