Menu

#10 Create java objects, static method and invoke static method

1.0
open
None
2021-10-18
2021-10-18
No

Create a class called Student and define private instance variables id, firstName, lastName and age.
Create a default constructor and create an object called rajin and assign values of id = 1000, firstName as your first name, lastName = your last name and age = 25. Print the values of this object using toString() method. Make sure to override toString() method of Object class. The easy steps is: right click inside class outside main method and go to Source option and then generate toString option. Then click Generate.
Create static method called as getStudent that returns Student object. Create another student object and then set values to id = 1001, firstName = "John", lastName= "Doe" and age = 30. Call it in Main method to print those values.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB