203FINAL
T or F: in Java you declare the type of variable in your code, and you can change the type of that variable later on
False
T or F: interfaces must have at least one constructor
False
T or F: We can store the integer values inside an arraylist using the following code: Arraylist <int>
False, it would be <Integer>
Which of the following is not True? In order to reduce dependency, we should decrease the number of attributes We should minimize the dependency as much as possible Abstraction is a technique for structuring computer programs Abstraction reduces things down to the simplest components possible
In order to reduce dependency, we should decrease the number of attributes
The specialized classes are said to...
Inherit the public methods and public and private instance variables of the general class
Constructors are used to _______
Initialize a newly created object
A derived class automatically has all the.....
Instance variables and public methods that the base class has, and it can have additional methods and/or instance variables as well.
______ defines only abstract behavior, thus it supports the OOP abstraction concept
Interface
Why is inheritance advantageous?
It allows classes to be reused, without having to copy it into the definitions{} of the derived class
Which statement is not true about local variables? Local variables can be used in any other method Local variables belong to methods Local variables are declared in the body of a method Local variables must be initialized
Local variables can be used in any other method
Which of the following is not an exception type? Error Memory Checked Runtime
Memory
What is the correct way to create an object called myObj of MyClass?
MyClass myObj = new MyClass();
Within Java, you need to code your program so that under certain conditions it will skip the current iteration of a for loop. What can be used to accomplish this?
continue
______ is a keyword that is used for checking if a reference variable is containing a given type of object reference or not. (If this object belongs to a particular class or not...)
instanceof
How do you create a variable with the numeric value 5?
int x = 5;
Which of the following statements is not true about JAVA?
it is an interpreted language
A _________ of a method is any externally observable data modification (state change)
side effect
_____ is a keyword which is used to access the methods or member variables of the parent class
super
Which statement is used to stop a loop?
break;
What is the expected output of the following code? public static void main(String args[]){int i = 0; do{System.out.println(i);i++;}while(i>5);}
0
What is the output fo the following code? public static void main(String args[]){ int x = 10; for(int y=0;y<5;y++,x--); System.out.print(""+x); }
10 9 8 7 6
Generic method definition
A method with one or more type parameters
Which statement is not true about the classes? The public interface of a class should be cohesive A class should represent a single concept In order to identify a class, we should look for the nouns All classes must include a main() method
All classes must include a main() method.
The purpose of generic methods is?
Allow type (int, string, etc. and user defined types) to be a parameter to methods, classes, and interfaces
______ is an unordered sequence that stores references to objects
Arraylist
Which of the following is not true about Unit Testing? A. The test cases are designed before or during the implementation B. Junit is a testing framework which automates the testing process C. Unit testing means testing one java file at a time D. We should run the test after each implementation change
C. Unit Testing means testing one java file at a time
Which keyword is used to create a class in Java?
Class
An inner class is part of another _____ or ____-
Class, method
Abstraction hides ______?
Complexity
To access a non-static inner class you must first do what?
Create an object of the outer class then create an object of the inner class
Assume you have two methods in the parent class: public void method1(){... } private void method2(){... } Which of the following is not possible for the inherited subclass? A. Public void method1(){...} B.Private void someOtherMethod(){...} C. Public void method2(){..} D. Private void method1(){...}
D. Private void method1(){...}
What is the result of the following code? int num = 6.45;
Error
Java uses ________ for much of its error handling.
Exceptions
Why use generic methods?
Generic enable types (classes and interfaces) to be parameters when defining class, interfaces and methods. They have stronger type checks at compile time, eliminate casts, and enable programmers to implement generic algorithms
What keyword is used to allow one class to use an interface?
Implements
What are some advantages of generics?
Increase reusability, type safety, elimination of type casting
Which of the following is true about abstract classes? It doesn't include any methods It forces the programmers to override a method The abstract classes don't have a class name It can be instantiated in the tester file
It forces the programmers to override a method
________ is used to run the bytecode on each platform
JVM Java Virtual Machine
Which java version were generics introduced?
Java 5
Which statement is not true about local variables?
Local variables can be used in any other method
What are the four types of inner classes?
Nested inner classes, method local inner classes, anonymous inner class, static nested classes
Can you use a primitive type as a class/interface type?
No!
An _____ inner class can not have a main() method while a _____ inner class can have a main() method delcared
Normal, static
Two or more methods with the same name in the same class with different arguments is called as _______
Overloading
When the child class declares a method that has the same type arguments as a method declared by its parent class is called ______
Overriding
Which data structure is used to store the values of functions calls? Hint: multiple function calls, function calls another function and it calls another function....
Stack
What does it mean for an inner class to be static?
That you can access it without creating an object for the outer class
Which of the following statements is not true about JAVA objects?
The object can only have one type of data
Which of the following statements is not true about Java object? The object is reusable The object can have only one type of data The object has operations The object has data
The object can only have one type of data
Which of the following statements is not true about JAVA?
The white spaces and indentation are important
______ refers to the object a method is being called on.
This
T or F: A derived class automatically has all the instance variables and public methods that the base class has, and it can have additional methods and/or instance variables as well
True
T or F: A static variable belongs to the class, not any object of the class
True
T or F: Accessor method does not change the internal data of the object on which it is invoked
True
T or F: An immutable class has no mutator methods
True
T or F: An inner class can be private
True
T or F: An interface type does not have instance variables
True
T or F: Do-while loop is guaranteed to run at least one time.
True
T or F: Every variable in Java needs a data type.
True
T or F: In the OOP concept, data and code are bound together by encapsulation
True
T or F: Java supports multilevel inheritance
True
T or F: Method overloading is a feature of OOPs which makes it possible to give the same name to more than one method within a class if the arguments that are passed differ
True
T or F: There is no need to create the object to call the static methods
True
T or F: Whenever we create a method, it should be either an accessor or mutator method, not both.
True
T or F: all methods of an interface are implicitly public and abstract
True
Which of the following is true about the public access modifier? Variables, methods, and constructors which are declared public can be accessed by any class in the same package. variables, methods and constructors which are declared public can be accessed only by the accessor methods of that class. Variables, methods and constructors which are declared public can be accessed by any class Variables, methods and constructors which are declared public in the superclass can only be accessed by its child class
Variables methods and constructors which are declared public can be accessed by any class.
Which of the following is true about Interfaces? It doesn't include any abstract method. We can implement multiple interfaces at the same time It must be defined inside another method It is not a valid reference type in Java
We can implement multiple interfaces at the same time.
If we need to create a class that needs to inherit the common features of multiple different classes, what should we do? We need to implement multiple interfaces The new class must be declared as an abstract class We must extend multiple classes and declare the new class as a subclass We need to create the class as an abstract class
We need to implement multiple interfaces
Which of the following statements is True about JAVA exceptions?
Finally block always executes
T or F: Java doesn't support multidimensional arrays.
False
T or F: Java is short for "JavaScript".
False
T or F: Mutator methods don't change the data of the object
False
T or F: String is a mutable class
False
T or F: The value of a string variable can be surrounded by single quotes
False
T or F: UML is an object oriented programming language
False
T or F: We can change the argument list of an overriding method
False
T or F: We can inherit from multiple abstract classes
False
T or F: We can only construct one object per class
False
If you want your condition to depend upon two conditions BOTH being true, what is the proper notation to put between the two Boolean statements?
&&
When defining generic classes, use _____ in definition
type variables, get/set
Which statement is not true about classes?
All classes must include a main() method
Consider the following code fragment. What is the printed output? public static void main(String argsI'm leaving now, i'll be home in a few minutes){ String str1 = "CS"; String str2 = "CS 203"; String str3 = "203"; String c = ""; String s1 = str1+str3; String s2 = str1 + "c"; String s4 = ""; s4 += str1; String s5 = s4 + str3; System.out.println(s5);}
CS203, because s4 = str1 and s5 = s4+str3
T or F: Abstract class is an OOP concept where one object can have many forms.
False
T or F: Abstract classes can be instantiated
False
T or F: Class is the base class (super class) of all classes in java
False
T or F: Code can be reused through inheritance thereby increasing redundancy.
False
T or F: In Java, we can compare int variable with a boolean
False
Which of the following statements is not true? There can be multiple variables referencing the same object. A reference is the location in memory that an object resides. References are mutable. The value of an object variable is a reference.
References are mutable.
Assume we have one superclass "Asset", and three subclasses: "Stock","Bond",and "Savings". Which of the following is not possible? Savings obj4 = new Asset(); Asset obj2 = new Stock(); Asset obj1 = new Bond(); Bond obj3 = new Bond();
Savings obj4 = new Asset();
Inheritance definition
The process by which a new class is created from another class
T or F: when we extend a superclass we have no choice whether or not to override the methods of the superclass
True
Which of the following statements is not true? A class depends on another class if its methods use that class in any way. We should place code for producing output/consuming input inside the constructor method. Always strive to decouple input and output from classes' work. We should reduce the dependency as much as possible.
We should place code for producing output/consuming input inside the constructor method.
Which of the following statements is true? You must initialize local variables Local variables belongs to the class Instance variables belong to the method Object references are set to zero
You must initialize the local variables
To declare an array in Java, define the variable type with:
[]
Which OOP concept forces the programmers to override a method
abstract classes
Type variables are instantiated with ____ or ____ types
class, interface
Which statement is not an access modifier in Java? protected inherited private public
inherited