Card 0 of 2
Consider the following C++ pseudocode:
Class Car {
const int wheels = 4;
float milesPerGallon;
string make;
string model;
}
Car sportscar = new Car;
What is the difference between the class car
, and the object sportscar
?
When programming within the Object-Oriented paradigm, think of the class as a blueprint, and the object as a house built from that blueprint.
The class Car
is a abstract specification that does not refer to any one particular instance. It is merely a protocol that all objects wishing to be cars should follow. The sportscar object is a realization of the car blueprint. It is a specific instance. In programming jargon, "sportscar
is instantiated from Car
."
Compare your answer with the correct one above
Consider the following JAVA code:
**public static void main(String[] args)**
**{**
**double number1 = 99.05;**
**int number2 = (int) number1;**
**System.out.println("number1 = " + number1);**
****System.out.println("number2 = " + number2);**
**}**
What would be the console output?
Type casting deals with assigning the value of a variable to another variable that is of a different type. In this case we have two variables one that is a double, and another that is an integer. number1 is a double that has a value of 99.05. However, when number2 is assigned the value of number1, there is some explicit type casting going on. When an integer is assigned the value of a double, it drops off the decimal places. This means that number2 has a value of 99.
Compare your answer with the correct one above