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

PR 6

java practical 6 for mit adt unevercity inloni kalbhor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

PR 6

java practical 6 for mit adt unevercity inloni kalbhor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Experiment No.

NAME: RAVIRAJ SATISH KHARADE ROLL NO- 74

Title:- Write a program to print the names of students by creating a Student class. If no name is passed
while creating an object of Student class, then the name should be "Unknown", otherwise the name
should be equal to the String value passed while creating object of Student class.

Source Code:
public class Student {
private String name;

public Student() {
this.name = "Unknown";
}

public Student(String name) {


this.name = name;
}

public String getName() {


return name;
}

public static void main(String[] args) {


Student student1 = new Student();
Student student2 = new Student("John");

System.out.println("Student 1 name: " + student1.getName());


System.out.println("Student 2 name: " + student2.getName());
}
}

You might also like