0

Classes and objects

So to access any part of a class or reference the class itself, you need to create an object right. Like if I had class Student, I would need to create an object, like Student s1 = new Student() to access that class. Also this may be a dumb question but why are we writing the Student class twice to make an object.

2nd Aug 2022, 11:45 AM
Tristan
2 Antworten
+ 2
Student s1 = new Student(); ^ specifies that the type of variable s1 Student s1 = new Student(); ^ means that we initialize the object of class Student that will be assigned to s1.
2nd Aug 2022, 12:10 PM
Lisa
Lisa - avatar
0
Or you may create a static object and do not initialize it
4th Aug 2022, 9:44 AM
Даниил Паклин
Даниил Паклин - avatar