Exam review Flashcards
(111 cards)
T/F
In a class, all methods except constructors can be overloaded when needed.
False.
Constructors can be overloaded.
T/F
The signature of a method only includes the method name and its parameter types. Does not include the type returned.
True
T/F Overloading happens when two or more methods in the same class have the same method name
True
T/F It is legal in java if 2 methods defined in the same class have the same name and parameter types by different return types
False
What is the value of str?
String str = “abc” + 4 + “fgh” + 5;
“abc4fgh5”
System.out.println (“"http:\www.queensu.ca"”); will display:
“http:\www.queensu.ca”
T/F
Static methods can’t call non-static methods.
True
T/F
Static methods can change values of non-static instance variables if they are in the same class.
False
T/F
Static methods can’t invoke static methods in the same class.
False
T/F
Static methods can always use “this” operators
False
T/F
A constructor has no type returned, not even void.
True
T/F
A constructor is a special type of methods that can be used to initialize the instance variables for an object.
True
T/F Every class can have at most one constructor and sometimes a class does not need a constructor when there is no need to initialize instance variables.
False
T/F
A constructor must have the same name as the class.
True
T/F
It must be declared outside of a class.
False
T/F
It must be in its own class.
False
T/F
It must have the keyword static.
True
T/F
It must have the keyword final
False
What does the following code print? public class Car { private String name; public Car(String name) { this.name = name; } public static void main(String[] args) { Car myFirstCar = new Car("Ford Fusion"); Car mySecondCar = new Car("Ford Fusion"); Car myThirdCar = new Car("Mazda 3"); if (myFirstCar != mySecondCar) System.out.println("My first car and second are not same."); else if (mySecondCar == myThirdCar) System.out.println("My second car and third are same."); else System.out.println("My second car and third are not same."); } }
My second car and third are not same.
BECAUSE MyFirstCar and MySecondCar do not reference the same object.
What is the output of the following code int vehicleType = 2; switch (vehicleType) { case 1: System.out.println("Passenger car."); case 2: System.out.println("Bus."); case 3: System.out.println("Truck."); default: System.out.println("Unknown vehicle class!"); break; }
Bus.
Truck.
Unknown vehicle class!
T/F
“Java has a two-step translation process to convert Java source programs to machine language. The output of the first step is called byte-code.”
True
What is the order that variables can be assigned in?
byte -> Short -> int -> long -> float ->double,
And Char hops in before int, but it cannot be a byte or short
T/F
“In procedural programming, procedures and data are clearly separated from each other, so it is easier to maintain and reuse code in procedural programming than in object oriented programming.”
False
What are the major components of a class?
Instance variables (attributes) and methods