You are on page 1of 22

Quiz 1 Sectiunea 4

1. When Eclipse launches, the Welcome page displays. Once this page is closed you cannot return
to the resources available on this page. True or False?
True
False (*)
2. Eclipse provides an edit area to help you navigate a hierarchy of information. True or False?
True
False (*)
3. Eclipse provides views to help you navigate a hierarchy of information. True or False?
True (*)
False
4. Tabs are used when more than one file is open in the edit area. True or False?
True (*)
False
5. A perspective is described as:
Mark for Review
o A combination of views and editors (*)
o A combination of views and windows
o A combination of editor tabs
o None of the above
6. The ______________ is the location onto which you will store and save your files.
o Perspective
o Workspace (*)
o Editor
o None of the above
7. A workspace can have one or more stored projects. True or false?

True (*)

False

8. Identify the components in the image below.

A-Main Method, B-Class, CPackage

A-Class, B-MainMethod, CPackage

A-Package, B-Main Method, CClass (*)

None of the above

9. In Eclipse, when you run a Java Application, the results may be displayed in the Console View.
True or False?
True (*)
False

Quiz 2 Sectiunea 4

Sectiunea 4

2. When importing another package into a class you must import the entire package as well as the
package classes that will be called. True or False?
True
False (*)
4. A counter used in a For loop cannot be initialized within the For loop statement. True or False?
True
False (*)
1.Which of the two diagrams below illustrate the
general form of a Java program?
Example A
Example B (*)

3. Which of the two diagrams below illustrate the correct syntax for variables used in an if-else
statement?
Example A (*)
Example B
5. The syntax below represents a valid initialization of a For loop counter. True or False?
public class ForLoop {
public static void main (String args[])
{
for (int i=10; i <20; i++)<
{System.out.println("i: "+i); }
}
}
True (*)
False
7.In a For loop, the counter is automatically incremented after each loop iteration. True or False?
True
False (*)
8. In an if-else construct, the condition to be evaluated must be contained within parentheses. True
or False?
True (*)
False

Quiz 3 Sectiunea 4
1. The six relational operators in Java are:
>,<,=,!,<=,>=
>,<,=,!=,=<,=>
>,<,=,!=,<=,>=
>,<,==,!=,<=,>= (*)
Sectiunea 4

2. Determine whether this boolean expression evaluates to true or false:


!(3<4&&5>6||6<=6&&7-1==6)
True

False (*)

3. The three logic operators in Java are:


!=,=,==
&&, ||, ! (*)
&&,!=,=
&,|,=
4. What will print if the following Java code is executed?

3 (*)

5. What is the difference between the symbols = and == ?


The symbol = is used in if statements and == is used in loops.
The symbol == is used to assign values to variables and the = is used in declarations.
The = is use to assign values to variables and the == compares values. (*)
There is no difference.
6. What is the output of the following lines of code?
int j=7,k=5,m=8,result; result=j/m*k; System.out.println(result);
0 (*)
4.375
0.175
280
7. What is the output of the following lines of code?
int j=7,k=5,m=8,result; result=j-k%3*m; System.out.println(result);
0
16
2
-9 (*)
8. Which of the following is not correct Java code?
double x=Math.sqrt(16);
double x=Math.pow(3,4)*5.0;
double x=Math.PI*5.0;
double x=Math.pow; (*)
9. Which line of Java code assigns the value of 5 raised to the power of 8 to a?
double a=15^8;
double a=Math.pow(5,8); (*)
int a=Math.pow(8,5);
int a=Math.pow(5,8);
double a=pow(8,5);
10. Write a declaration statement that will hold a number like 2.541.
char number;
int number;
float number; (*)
boolean number;
11. Which of the following is the name of a Java primitive data type?
String
Sectiunea 4

int (*)
Rectangle
Object

12. Which of the following is not a legal name for a variable?


R2d2
dgo2sleep
4geeks (*)
to_be_or_not_to_be
13. Which of the following examples of Java code is not correct?
int x=6;
double d=4.5;
boolean b=1; (*)
char c='r';
14. Which of the following statements correctly assigns "3 times 10 to the 4th power" to the
variable number?
double number=3*10^4;
double number=3(e4);
double number=3e4; (*)
double number=3*10e4;
15. Which line of code does not assign 3.5 to the variable x?
double x=3.5
x=3.5;
3.5=x; (*)
x=7.0/2.0;
16. Consider the following:
You are writing a class and are using a global variable. Inside a method you declare a local
variable with the same name as the global variable.
This programming style is poor because inside the method the global variable will have
precedence over the local variable with the same name.
True or false?
True
False (*)
17. What will the method
methodA print to the screen?
18 (*)
15
6
3

18.Which line of Java code properly calculates the volume of a cone using

where r and h are Java primitive integers?


double V=1/3*3.14*r*r*h;
double V=(double)1/3*Math.PI*Math.pow(r,2)*h; (*)
double V=1/3*Math.PI*Math.pow(r,2)*h;
double V=(double)1/3*Math.PI*Math.pow(2,r)*h;
Sectiunea 4

double V=1/3*3.14*r(2)*h;

19. Given the following declaration: int z=5,m=6;


Which line of Java code properly casts one type into another without data loss?
double x=(double)z/m; (*)
double x=z/m;
double x=(double)(z/m);
double x= double z/m;

Quiz 1 Sectiunea 5
1. What is a loop?
A keyword used to skip over the remaining code.
A set of logic that is repeatedly executed until a certain condition is met. (*)
A segment of code that may only ever be executed once per call of the program.
None of the above.
2. It is necessary to end all loops at some point in your Java program. True or false?
True (*)
False
3. Which of the following are types of loops in Java?
While (*)
If/Else
Do-While (*)
For (*)
4. Identify which situation could be an example of a WHILE loop.
Taking coins out of a pile one at a time and adding their value to the total until there are no
more coins in the pile to add.
Attending class while school is not over for the day.
Petting each animal at the pet store one at a time until all the animals have been petted.
All of the above. (*)
5. Which of the following correctly initializes a For loop that runs through 5 times?
for(int i = 0; i == 6; i++)
for(int i = 1; i < 6; i++) (*)
for(int i = 0; i < 5; I++)
for(int i = 1; i < 5; I++)
6. What is the function of the word "break" in Java?
It exits the current loop or case statement. (*)
It continues onto the next line of code.
It stops the program from running.
It does not exist in Java.
7. The following code fragment properly implements the switch statement. True or false?
default(input)
switch '+':
answer+=num;
break;
case '-':
answer-=num;
break;
!default
Sectiunea 4

System.out.println("Invalid input");
True
False (*)
8. What is one significant difference between a WHILE loop and a DO-WHILE loop?
There is no difference between a DO-WHILE loop and a WHILE loop.
A DO-WHILE loop does not exist in Java and a WHILE loop does.
A DO-WHILE loop includes an int that serves as a counter and a WHILE loop does not.
A DO-WHILE loop will always execute the code at least once, even if the conditional
statement for the WHILE is never true. A WHILE loop is only executed if the conditional
statement is true. (*)
9. Which of the following correctly initializes an instance of Scanner, called "in", that reads input
from the console screen?
Scanner in = new Scanner(System.in); (*)
Scanner in = new Scanner("System.in");
Scanner in = Scanner(System.in);
System.in in = new Scanner();

Quiz 2 Sectiunea 5
1. Which of the following creates a class named Diver with one constructor, and 2 instance
variables maxDepth and certified?

(*)

2. The basic unit of encapsulation in Java is the:


class (*)
method

classpath
package

3. Which of the following creates a Object from the Animal class listed below?
Sectiunea 4

Animal dog=new Animal();


Animal dog=new Animal(50,30); (*)
Animal dog=Animal(50,30);
Animal dog=new Animal(50);

4. Complete the sentence. A constructor...


must have the same name as the class it is declared within.
is used to create objects.
may be declared public.
is all of the above. (*)

5. The following code creates an Object of type Animal:


Animal a;
True
False (*)
6. Which of the following creates an object from the Car class listed below?

Car c = new Car(3000, "Toyota"); (*)


Car c=new Car;
Car c=Car();
Car c;
Car c =new Car();

7. What is wrong with the following class declaration?


Classes cannot include strings.
Classes cannot include mixed data types.
There is no constructor method and you have
to make a constructor method.
There is nothing wrong. (*)
8. Which of the following is true?
In Java, a method declared public generates a compilation error.
int is the name of a class available in the package java.lang.
Instance variable names may only contain letters and digits.
A class always has a constructor (possibly automatically supplied by the java compiler). (*)
The more comments in a program, the faster the program runs.
9.What value will be returned when the setValue method is called?

Sectiunea 4

35

36

37 (*)

38

10. The return value of a method can only be a primitive type and not an object. True or false?
True
False (*)
11 The following statement compiles and executes. What can you say for sure?
submarine.dive(depth);
Depth must be an int.
Dive must be a method. (*)
Dive must be the name of an instance field.
Submarine must be the name of a class.
Submarine must be a method.
12.Which of the following calls the method moveUp in the class below:
Puzzle p=new Puzzle();
p.moveUp(3,4);
PuzzlePiece p=new PuzzlePiece();
p.moveUp(3,4); (*)
PuzzlePiece p=new PuzzlePiece();
p.moveUp(3,4,5);
Puzzle p=new Puzzle();
p.moveUp(3,4,5);
13. A class can have multiple constructors. True or false?

True (*)

14. The constructor of a class has the same name as the class. True or false? True (*)

False
False

15. Which of the following adds a constructor to the class below?

Sectiunea 4

(*)
16. What operator do you use to call an object's constructor method and create a new object?
new (*)
class
instanceOf
17. Consider: public class MyClass{ public MyClass(){/*code*/} // more code...}
To instantiate MyClass, what would you write?
MyClass m = new MyClass(); (*)
MyClass m = new MyClass;
MyClass m = MyClass;
MyClass m = MyClass();
18. Which of the following may be part of a class definition?
instance variables
instance methods
constructors
comments
all of the above (*)
19. What is garbage collection in the context of Java?
The operating system periodically deletes all of the Java files available on the system.
Any package imported in a program and not used is automatically deleted.
When all references to an object are gone, the memory used by the object is automatically
reclaimed. (*)
The JVM checks the output of any Java program and deletes anything that does not make
sense.
20. Which of the following keywords are used to access the instance variables of an object from
within the class code for that object?
public
private
protected
Sectiunea 4

this (*)

21. Which constructor code populates the instance variables of the class correctly?

(*)

Quiz 1 Sectiunea 6
1. Which of the following statements is a valid array declaration?
int number();
float average[]; (*)
double[] marks; (*)
counter int[];
2.The following array declaration is valid: int[] y = new int[5];

True (*)

False

3. Which of the following declares a one dimensional array named "score" of type int that can hold
9 values?
int score;
int[] score;
int[] score=new int[9]; (*)
int score=new int[9];
4. Which of the following declares and initializes a two dimensional array?
int[][] array={{1,1,1},{1,1,1},{1,1,1}}; (*)
int[] array={{1,1,1},{1,1,1},{1,1,1}};
int[][] array={1,1,1},{1,1,1},{1,1,1};
int[][] array={1,1,1,1,1,1,1,1,1};
5. Which of the following declares and initializes a one dimensional array named words of size 10
so that all entries can be Strings?
String words=new String[10];
char words=new char[10];
char[] words=new char[10];
String[] words=new String[10]; (*)
6.

What is the output of the following segment of code?


222220
Sectiunea 4

10

7. What is the output of the following segment of code?

0 (*)
220
2
This code does not compile.
1286864
643432
262423242322
666666 (*)
This code does not compile.

8. Which of the following declares and initializes a two dimensional array named values with 2
rows and 3 columns where each element is a reference to an Object?
String[][] values={"apples","oranges","pears"};
String[][] values=new String[3][2];
String[][] values=new String[2][3]; (*)
String[][] values;
9. Which of the following declares and initializes a two dimensional array where each element is a
reference type?
String words=new String[10];
char[][] words;
char[][] words=new char[10][4];
String[][] words=new String[10][3]; (*)
10.
Which of the following statements print every element of the one dimensional array prices
to the screen?
for(int i=0; i < prices.length; i++){System.out.println(prices[i]);} (*)
System.out.println(prices.length);
for(int i=1; i <= prices.length; i++){System.out.println(prices[i]);}
for(int i=0; i <= prices.length; i++){System.out.println(prices[i]);}
11. What is the output of the following segment of code?
753
6
7766554433221
7531 (*)
This code does not compile.
12.
The following creates a reference in memory named y that can refer to five different integers
via an index. True or false? int[] y = new int[5];
True (*)
False
13. The following creates a reference in memory named z that can refer to seven different doubles
via an index. True or false? double z[] = new double[7];
True (*)
False
14. What is the output of the following segment of code if the command line arguments are "apples
oranges pears"?
apples

Sectiunea 4

11

pears (*)
oranges
args
This code doesn't compile.

15. What is the output of the following segment of code if the command line arguments are "apples
oranges pears"?
0
1
2
3 (*)
This code does not compile.
16. What will be the content of array variable table after executing the following code?

000
000
000
100
010
0 0 1 (*)
100
110
111
001
010
100
17.What is the output of the following segment of code?

1286864 (*)
643432
262423242322
666666
This code does not compile.

18. After execution of the following statement, which of the following are true?
int number[] = new int[5];
number[0] is undefined
number[4] is null
number[2] is 0 (*)
number.length() is 6
19. The following array declaration is valid. True or false?int x[] = int[10];
False (*)

True

Quiz 2 Sectiunea 6
1. Consider the following code snippet. What is printed?
String river = new String("Hudson"); System.out.println(river.length());
6 (*)
7
8
Hudson
Sectiunea 4

river
12

2. Which of the following creates a String reference named str and instantiates it?
String str;
str="str";
String s="str";
String str=new String("str"); (*)
3. Declaring and instantiating a String is much like any other type of variable. However, once
instantiated, they are final and cannot be changed. True or false?
True (*)
False
4. Which of the following statements declares a String object called name?
String name; (*)
String name
int name;
double name;
5. Suppose that s1 and s2 are two strings. Which of the statements or expressions are valid?
String s3 = s1 + s2; (*)
String s3 = s1 - s2;
s1 <= s2
s1.compareTo(s2); (*)
int m = s1.length(); (*)
6. Consider the following code snippet. What is printed?

PoliiPolii (*)
Polii
auaacauaac
auaac
ArrayIndexOutofBoundsException is thrown

7. What will the following code segment output?

"\\\\\"
\"\\\\\"
"\\" (*)

""\\"
""\"
""\

"\\\"
8. What will the following code segment output?

" (*)
"""\
""
""\
""
9. The following program prints "Equal". True or false?
True (*)
Sectiunea 4

13

False

10. Which of the following creates a


String named string?
char string;
String s;
String string; (*)
String String;
String char;
11. Given the code, which of the following would equate to true?
String s1 = "yes";
String s2 = "yes";
String s3 = new String(s1);
s1 == s2 (*)
s1 = s2
s3 == s1
s1.equals(s2) (*)
s3.equals(s1) (*)
12. The String methods equals and compareTo perform the exact same function. True or false?
True
False (*)
13. The == operator can be used to compare two String objects. The result is always true if the two
strings are identical. True or false?
True
False (*)
14. The following program prints "Equal". True or false?

True

False (*)

15. Given the code below, which of the following calls are valid?
String s = new String("abc");
s.trim() (*)
s.replace('a', 'A') (*)
s.substring(2) (*)
s.toUpperCase() (*)
s.setCharAt(1,'A')
16. Consider the following code snippet. What is printed?
String ocean = new String("Atlantic Ocean"); System.out.println(ocean.indexOf('a'));
0
2
3 (*)
11
12
17. Consider the following code snippet. What is printed?

55555
87668 (*)
Sectiunea 4

14

AtlanticPacificIndianArcticSouthern
The code does not compile.
An ArrayIndexOutofBoundsException is thrown.

18. Consider the following code snippet. What is printed?

55555
87658
AtlanticPacificIndianArcticSouthern
The code does not compile.
An ArrayIndexOutofBoundsException is thrown. (*)

19.How would you use the ternary operator to rewrite this if statement?
if (skillLevel > 5)
numberOfEnemies = 10;
else
numberOfEnemies = 5;

numberOfEnemies = ( skillLevel > 5) ? 5 : 10;


numberOfEnemies = ( skillLevel < 5) ? 10 : 5;
numberOfEnemies = ( skillLevel >= 5) ? 5 : 10;
numberOfEnemies = ( skillLevel >= 5) ? 10 : 5;
numberOfEnemies = ( skillLevel > 5) ? 10 : 5; (*)
20. How would you use the ternary operator to rewrite this if statement?
if (gender == "male")
System.out.print("Mr.");
else
System.out.print("Ms.");
System.out.print( (gender == "male") ? "Mr." : "Ms." ); (*)
System.out.print( (gender == "male") ? "Ms." : "Mr." );
(gender == "male") ? "Mr." : "Ms." ;
(gender == "male") ? "Ms." : "Mr." ;

Quiz 3 Sectiunea 6
1. Which of the following would give you an array index out of bounds exception?
Misspelling a variable name somewhere in your code.
Refering to an element of an array that is at an index less than the length of the array minus
one.
Using a single equal symbol to compare the value of two integers.
Refering to an element of an array that is at an index greater than the length of that array
minus one. (*)
Unintentionally placing a semicolon directly after initializing a for loop.
Sectiunea 4

15

2. What exception message indicates that a variable may have been mispelled somewhere in the
program?
variableName cannot be resolved to a variable (*)
method methodName(int) is undefined for the type className
Syntax error, insert ";" to complete statement
All of the Above
3. Which of the following defines an Exception?
A very severe non-fixable problem with interpreting and running your code.
Code that has no errors and therefore runs smothly.
A problem that can be corrected or handled by your code. (*)
An interpreter reading your code.
4. What do exceptions indicate in Java?
The code has considered and dealt with all possible cases.
A mistake was made in your code. (*)
There are no errors in your code.
Exceptions do not indicate anything, their only function is to be thrown.
The code was not written to handle all possible conditions. (*)
5. Which line of code shows the correct way to throw an exception?
new throw Exception("Array index is out of bounds");
throw new Exception("Array index is out of bounds"); (*)
throw Exception("Array index is out of bounds");
throws new Exception("Array index is out of bounds");
6. What does the interpreter look for when an exception is thrown?
It does not look for anything. It just keeps reading through your code.
It does not look for anything. It stops interpreting your code.
The end of the code.
A catch statement in the code. (*)
7. Which of the following would be a correct way to handle an index out of bounds exception?
Throw the exception and catch it. In the catch, set the index to the index of the array closest
to the one that was out of bounds. (*)
Do nothing, it will fix itself.
Throw the exception that prints out an error message. There is no need to have the catch
handle the exception if it has already been thrown.
Rewrite your code to avoid the exception by not permititng the use of an index that is not
inside the array. (*)
8. A computer company has one million dollars to give as a bonus to the employees, and they wish
to distribute it evenly amongst them.
The company writes a program to calculate the amount each employee receives, given the number
of employees.
Unfortunately, the employees all went on strike before they heard about the bonus. This means that
the company has zero employees.
What will happen to the program if the company enters 0 into the employment number?
Sectiunea 4

16

An unfixable error will occur.


The program will calculate that each employee will receive zero dollars because there are
zero employees.
An exception will occur because it is not possible to divide by zero. (*)
The programmers will have proven their worth in the company because without them the
company wrote faulty code.

Quiz 1 Sectiunea 7
1. Following good programming guidelines, what access modifier should be used for the class fields
in the following situation?
A car insurance company wants to create a class named Customer that stores all data for a
specified customer including the fields: vehicle information, policy information, and a credit card
number.
Public
Protected
Private (*)
Default
All of the above
2. A team is working on a coding project. They desire that all portions of their code should have
access to the classes that they write. What access modifier should be used for each class?
Public (*)
Protected
Private
Default
All of the above
3. Which of the following could be a reason to need to pass an object into a method?
Easier access to the information contained within the object.
The ability to make changes to an object inside of the method.
Comparing two objects.
All of the above. (*)
4. Which of the following shows the correct way to initialize a method DolphinTalk that takes in 2
integers, dol1 and dol2, and returns the greater int between the two?
int DolphinTalk(dol1, dol2){ if(dol1 > dol2) return dol1; else return dol2;}
int DolphinTalk(int,int){ if(dol1 > dol2) return dol1; else return dol2;}
int DolphinTalk(int dol1,int dol2){ if(dol1 > dol2) return dol1; else return dol2;} (*)
int DolphinTalk, int dol1,int dol2 { if(dol1 > dol2) return dol1; else return dol2;}
All of the above
5. Cameron wishes to write a method that takes in two objects and returns the one with the greatest
value. Is this possible?
Yes, but he will have to use two different methods, one to take in the objects and the other to
return an object.
Yes, methods can take objects in as parameters and can also return objects all within the
same method. (*)
No, it is not possible to return objects.
Sectiunea 4

17

No, it is not possible to have objects as parameters or to return objects.

6. You are assigned to write a method that compares two objects of type Career. One requirement of
your assignment is to have your method compare the "greatestPossibleSalary" instance data of
Career objects. The "greatestPossibleSalary" field is data type int.
What would be the best return type from your compare method?
Career, because if it returns the highest paying Career object it will be able to use the same
method later to compare other aspects of Career objects. (*)
Integer, because it is the easiest to code with.
String, because is should return a string of the name of the career that is highest paying
because none of the other information of the career matters.
Array, because it can store the most information.
7. Consider the following: There is a method A that calls method B. Method B is a variable
argument method. With this, which of the following are true?
Method A can invoke method B twice, each time with a different number of arguments. (*)
A compliler error will result since method B does not know how large an array to create
when it is invoked by method A.
When invoked, method B creates an array to store some or all of the arguments passed to it
from method A. (*)
All of the above.
8. What type(s) would work for a variable argument method?
Integers, Strings, and Booleans (*)
Constructors
Arrays (*)
Objects (*)
All of the above
9. It is possible to have more than one constructor with the same name in a class, but they must
have different parameters. True or false?
True (*)
False
10. Which of the following is a possible way to overload constructors?

(*)
Sectiunea 4

18

Quiz 2 Sectiunea 7
1. Static variables can't use which of the following specifiers?
Public
Protected
Friendly (*)
Default
Private
2. You can assign new values to static variables by prefacing them with the this keyword and a dot
or period. True or false?
True (*)
False
3. Which of the following statements about static methods is true?
They exist once per class. (*)
They exist once in each instance.
They can be overridden by a subclass.
They can access any instance variable.
They cannot access static variables declared outside the method.
4. You can create static class methods inside any Java class. True or false? True (*)

False

5. You can return an instance of a private class through a static method of a different class. True or
false?
True
False (*)
6. You can create static classes as independent classes. True or false?
True
False (*)
7. You can use an inner static class to return an instance of its outer class container. True or false?
True (*)
False
8. A linear recursive method can call how many copies of itself?
1 (*)
2 or more
None
9. Which case does a recursive method call last?
Recursive Case
Convergence Case
Basic Case
Base Case (*)
None of the above
10. A non-linear recursive method can call how many copies of itself?
1
Sectiunea 4

19

2 or more (*)
None

Quiz 3 Sectiunea 7
1. What is a UML?
Unidentified Molding Level, the level of access permitted by the default access specifier.
Unified Modeling Language, a standardized language for modeling systems and structures
in programming. (*)
Universal Model Light, a program that reads the brightness of any given lightbulb.
None of the above.
2. What does it mean to inherit a class?
The subclass (or child class) gains access to any non-private methods and variables of the
superclass (or parent class). (*)
The access specifier has been set to private.
A way of organizing the hierarchy of classes.
Extending a method from a superclass.
3. Which of the following correctly defines a superclass (or parent class)?
A class that inherits methods and fields from a more general class.
The most specific class of a hierarchy system of classes.
A class that passes down its methods to more specialized classes. (*)
A keyword that allows or restricts access to data and methods.
4. Which of the following correctly defines a subclass (or child class)?
A class that inherits methods and fields from a more general class. (*)
A keyword that allows or restricts access to data and methods.
A class that passes down its methods to more specialized classes.
The most general class of a hierarchy system.
5. Methods are generally declared as public so other classes may use them. True or false?
True (*)
False
6. Which is the most accurate description of the code reuse philosiphy?
A programming philosophy that promotes stealing your classmates' code.
A programming philosophy that promotes having no concern about the security of code.
A programming philosophy that promotes protecting data and hiding implementation in
order to preserve the integrity of data and methods.
A programming philosophy that promotes simpler, more efficient coding by using existing
code for new applications. (*)
7. Which of the following correctly describes the use of the keyword super?
A keyword that restricts access to only inside the same class.
A keyword that allows subclasses to access methods, data, and constructors from their
parent class. (*)
A keyword that signals the end of a program.
A keyword that allows access from anywhere.
8. Which of the following is the proper way to set the public variable length of the super class equal
to 5 from inside the subclass?
super.length() = 5
Sectiunea 4

20

super.length(5)
super.length = 5 (*)
super(length = 5)
9. What is a hierarchy?
A programming philosophy that promotes simpler, more efficient coding by using existing
code for new applications.
A programming philosophy that promotes protecting data and hiding implementation in
order to preserve the integrity of data and methods.
A keyword that allows subclasses to access methods, data, and constructors from their
parent class.
A structure that categorizes and organizes relationships among ideas and concepts of things
with the most general at the top and the most specific at the bottom. (*)
10. It is possible to extend a class that already exists in Java, such as the Applet class. True or false?
True (*)
False

Quiz 4 Sectiunea 7
1. Why would a programmer use polymorphism rather than sticking to a standard array?
Because arrays only work using the same object type and polymorphism provides a way
around this. (*)
Because it is easier to add or remove objects using polymorphism even when all of the
objects are of the same type.
Because arrays are more complex and polymorphism simplifies them by restricting them to
only contain the same type objects.
A programmer wouldn't use polymorphism over a standard array.
2. It is possible to override methods such as equals() and toString() in a subclass of Object to fit the
needs of the objects of the subclass. True or false?
True (*)
False
3. Is there a difference between overriding a method and overloading a method?
Yes. Overriding is done within a single class and overloading is done through a series of
superclasses and their subclasses.
Yes. Overriding allows for the creation of an array of different object types and overloading
restricts an array to only contain the same object types.
Yes. Overriding is done in the subclass and allows for redefining a method inherited from
the superclass and overloading is done within a class and allows for multiple methods with
the same name. (*)
No, they are the same.
4. Which of the following is a goal of the object model?
Providing modular code that can be reused by other programs or classes. (*)
Concealing implementation. (*)
Data abstraction. (*)
Protecting information and limiting other classes' ability to change or corrupt data. (*)
5. If Sandal extends Shoe, it is possible to declare an object such that
Sandal s = new Shoe();
True

False (*)

6. What allows Java to correctly and automatically determine which method to invoke based on the
type of object being referred to at the time the method is called?
Sectiunea 4

21

Abstract classes
Polymorphism
Inheritance
Dynamic Method Dispatch (*)

7. Which of the following are true about an abstract class?


It is possible to create objects of this type.
The Java Virtual Machine does not differentiate abstract classes from concrete classes.
It is possible to create references of this type. (*)
It is identified by the Java keyword abstract. (*)

Sectiunea 4

22