Question 41
MediumA class Student has 3 instance variables and a static variable totalStudents. 50 Student objects are created. How many copies of totalStudents exist?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
A class Student has 3 instance variables and a static variable totalStudents. 50 Student objects are created. How many copies of totalStudents exist?
3
50
1
150
Sign up free to see the answer and a step-by-step explanation.
A class Car has a method getSpeed() that is called on two different Car objects. How does the method know which object's speed to return?
Through a global variable
It needs the speed passed as an argument
Through the implicit reference to the calling object (this or self)
It returns the speed of the last car created
Sign up free to see the answer and a step-by-step explanation.
Which is the best example of an object, rather than a class?
The blueprint of a house
BankAccount
The account with number 1023 and balance ₹5,000
The concept of a vehicle
Sign up free to see the answer and a step-by-step explanation.
A class has only static methods and a private constructor, such as Java's Math. What is it used as?
An interface
A singleton with state
A utility class whose methods are called without creating objects
An abstract class
Sign up free to see the answer and a step-by-step explanation.
In C++, what does the 'this' pointer hold inside a member function?
The address of the function
The address of the object the function was called on
The address of the class
NULL
Sign up free to see the answer and a step-by-step explanation.
What is wrong with this Java constructor: Point(int x, int y) { x = x; y = y; }?
Nothing is wrong
It assigns the parameters to themselves; it should use this.x = x and this.y = y
The constructor must return a Point
Constructors cannot take parameters
Sign up free to see the answer and a step-by-step explanation.
A class Temperature stores Celsius and needs a way to build an object from Fahrenheit. Which design is clearest?
A static factory method such as Temperature.fromFahrenheit(98.6)
A global variable
A second constructor with the same parameter type
Making the field public
Sign up free to see the answer and a step-by-step explanation.
In Python, what does str control?
Which class it inherits from
How much memory it uses
The string shown by print(obj) and str(obj)
How the object is compared
Sign up free to see the answer and a step-by-step explanation.
In Python, two objects are created with equal values but no eq is defined. What does obj1 == obj2 return?
False, because the default compares identity
None
True
An error
Sign up free to see the answer and a step-by-step explanation.
Which is true about objects stored in a Java ArrayList<Student>?
Objects are converted to strings
The list holds copies of each object's fields
Each object is stored on the stack
The list holds references to Student objects on the heap
Sign up free to see the answer and a step-by-step explanation.