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?
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.
+ 1
you should read up on the basic concepts of OOP programming languages