0

What is the use of objects in calling methods of the classes?plz tell me

class Student{ int rollno; String name; void insertRecord(int r, String n){ rollno=r; name=n; } void displayInformation(){System.out.println(rollno+" "+name);} } class TestStudent4{ public static void main(String args[]){ Student s1=new Student(); Student s2=new Student(); s1.insertRecord(111,"Karan"); s2.insertRecord(222,"Aryan"); s1.displayInformation(); s2.displayInformation(); } } Here what is the role played by s1 and s2?

6th Apr 2017, 3:15 AM
anurag modi
anurag modi - avatar
2 Answers
+ 7
s1 and s2 are objects means two entities that can be differentiated by inserting different values to their associated variables. Because of OOP, you dont have to make single function or variable for every object you make. Object oriented programming is used for resuability of code. For thousands number of objects, displayinformation() and insertRecord() is used.
6th Apr 2017, 4:13 AM
Sachin Artani
Sachin Artani - avatar
+ 1
you should read up on the basic concepts of OOP programming languages
6th Apr 2017, 3:35 AM
Edward