Sie sind auf Seite 1von 29

Section 4 Oracle Java Fundamental Quiz

Section 4 Quiz
(Answer all questions in this section)

1. What will the following code segment output?

"\\" (*)

2. The String methods equals and compareTo perform similar functions and differ in
their return type. True or false? Mark for Review
True (*)

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

String river = new String("Hudson"); System.out.println(river.length());


6 (*)

4. Which of the following defines a driver class? Mark for Review


(1) Points
Contains a main method and other static methods. (*)

5. The following defines a class keyword:


Precedes the name of the class. (*)

6. Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review.
(1) Points
Example A
Example B (*)

7. When importing another package into a class you must import only the package
classes that will be called and not the entire package. True or false?
False (*)

8. What two values can a boolean variable have? Mark for Review
(1) Points
True and false (*)

9. Which line of Java code assigns the value of 5 raised to the power of 8 to a?
double a=Math.pow(5,8); (*)

10. What is the output of the following lines of code?

int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result);
2 (*)
11. What will the method methodA print to the screen?

18 (*)

12. Write a declaration statement that will hold a number like 2.541.
float number; (*)

13. For every opening curly brace { there must be a closing curly brace} or the
program will not compile without error. True or False?
False (*)

14. You can return to the Eclipse Welcome Page by choosing Welcome from what
menu?
Help (*)

15. Tabs are used when more than one file is open in the edit area. True or False?
True (*)

1. 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? False (*)

2. Which of the following statements correctly assigns "3 times 10 to the 4th power"
to the variable number?double number=3e4; (*)

3. Which line of code does not assign 3.5 to the variable x? Mark for Review
(1) Points
3.5=x; (*)
4. A local variable has precedence over a global variable in a Java method. True or
false?
True (*)
5. What does the following program output?

total cost: 40 (*)

6. For every opening curly brace { there must be a closing curly brace} or the
program will not compile without error. True or False?
True (*)

7. The ______________ is the location into which you will store and save your files.
Workspace (*)

8. What symbols are required for a compiler to ignore a comment?


// (*)

9. The following program prints "Equal". True or false?

False (*)

10. Suppose that s1 and s2 are two strings. Which of the statements or expressions are
valid?
(Choose all correct answers)
String s3 = s1 + s2; (*)
s1.compareTo(s2); (*)
int m = s1.length(); (*)

11. 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 (*)

12. The following defines a package keyword: Mark for Review


(1) Points
Defines where this class lives relative to other classes, and provides a level of
access control. (*)

13. The following defines a class keyword:


Precedes the name of the class. (*)

14. The following defines a class keyword:


Precedes the name of the class. (*)
15. 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?
False (*)

1. Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its
respective data type.
char, int, double, long, String (*)

2. Which line of Java code will assign the value of the square root of 11 to a variable
named a?
double a=Math.sqrt(11); (*)

3. Which of the following statements displays 12345?


I. System.out.println( 123 * 100 + 45);
II. System.out.println("123" + 45);
III. System.out.println( 12 + "345"); Mark for Review
(1) Points
All of the above. (*)

4. 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?
False (*)

5. Select the declaration and initialization statement that will hold the letter J.
char letter='J'; (*)

6. For every opening curly brace { there does not need to be a closing curly brace}
for the program to compile without error. True or False?
False (*)

7. Two variables are required to support a conversion of one unit of measure to


another unit of measure. True or False?
True (*)

8. Eclipse provides views to help you navigate a hierarchy of information. True or


False?\
True (*)
9. The == operator can be used to compare two String objects. The result is always
true if the two strings are identical. True or false?
False (*)

10. Consider the following code snippet

String forest = new String("Black");


System.out.println(forest.length());

What is printed?\5 (*)

11. The following program prints "Equal". True or false?


True(*)

12. The following defines a package keyword:


Defines where this class lives relative to other classes, and provides a level of
access control. (*)

13. Which of the two diagrams below illustrate the general form of a Java program?

Mark for Review


(1) Points
Example A
Example B (*)
14. Which of the two diagrams below illustrate the general form of a Java program?

Mark for Review


(1) Points
Example A
Example B (*)

15. Which of the following defines a driver class?


Contains a main method and other static methods. (*)

1. In Eclipse, when you run a Java Application, the results are displayed in a new
window. True or False?
False (*)

2. Multiple windows are used when more than one file is open in the edit area. True
or False?
False (*)

3. What is the purpose of the Eclipse Editor Area and Views?


(Choose all correct answers)
To modify elements. (*)
To navigate a hierarchy of information. (*)

4. The following defines an import keyword: Mark for Review


(1) Points
Provides the compiler information that identifies outside classes used within
the current class. (*)
5. The following defines a package keyword :
Defines where this class lives relative to other classes, and provides a level of
access control. (*)

6. The following defines a class keyword


Precedes the name of the class. (*)

7. The following defines a class keyword


Precedes the name of the class. (*)

8. The following code is an example of creating a String reference:


String s;
True or false?
(1) Points
True (*)

9. Which of the following statements declares a String object called name?


String name; (*)

10. Given the code below, which of the following would equate to true?

String s1 = "yes";
String s2 = "yes";
String s3 = new String(s1);
Mark for Review
(1) Points

(Choose all correct answers)


s1 == s2 (*)
s3.equals(s1) (*)
s1.equals(s2) (*)

11. Which line of Java code will assign the value of the square root of 11 to a variable
named a?
double a=Math.sqrt(11); (*)

12. Which line of Java code assigns the value of 5 raised to the power of 8 to a?
double a=Math.pow(5,8); (*)

13. Which line of Java code properly calculates the area of a triangle using
A=1/2(b)(h) where b and h are Java primitive integers?
double A=(double)1/(double)2*b*h; (*)

14. 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 (*)

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


2bad (*)

1. What is the purpose of the Eclipse Editor Area and Views?


(Choose all correct answers)
To modify elements. (*)
To navigate a hierarchy of information. (*)

2. A _______________ is used to organize Java related files


Package (*)

3. A workspace can have one or more stored projects. True or false


True (*)

4. Which of the two diagrams below illustrate the general form of a Java program?

Mark for Review


(1) Points
Example A
Example B (*)

5. The following defines a class keyword :


Precedes the name of the class. (*)
6. The following defines a package keyword
Defines where this class lives relative to other classes, and provides a level of
access control. (*)

7. Which of the two diagrams below illustrate the general form of a Java program?

Mark for Review


(1) Points
Example A
Example B (*)

8. Examine the following code:

What is the value of variable x?


2 (*)

9. Which of the following is not correct Java code


double x=Math.pow; (*)

10. 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 (*)

11. What is the output of the following lines of code?

int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result);
2 (*)

12. What two values can a boolean variable have?


True and false (*)

13. What is printed by the following code segment?

\\\\\\\ (*)

14. 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 (*)

15. Consider the following code snippet.

What is printed?
ArrayIndexOutofBoundsException is thrown (*)

1. Which the line of code does not assign 3.5 to the variable x?
3.5 = X(*).

2. A workspace is :
All of the Above(*)

3. Consider the following code snippet


String[] mountains =
{Chimborazo,Matterhorn,Olympus,Everest,Kinabalu,
Adriondack,Blue Ridge,Zugspitze,};
For(int i = 0; i < 5; i++)
System.out.print(mountains.length);

88888(*)
SECTION 5

Section 5 Oracle Java Fundamental Quiz


Section 5 Quiz
(Answer all questions in this section)

1. Which of the following could be a reason to use a switch statement in a Java program
Because it allows the program to run certain segments of code and neglect to run others
based on the input given. (*)

2. The three logic operators in Java are :


&&, ||, ! (*)

3. Which of the two diagrams below illustrate the correct syntax for variables used in an if-
else statement?

Example A (*)
Example B

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


False (*)

5. The six relational operators in Java are :


>,<,==,!=,<=,>= (*)

6. How would you use the ternary operator to rewrite this if statement?
if (skillLevel > 5)
numberOfEnemies = 10;
else
numberOfEnemies = 5;
numberOfEnemies = ( skillLevel > 5) ? 10 : 5; (*)
7. What will print if the following Java code is executed?

if ((5.1 > 4.3 && 6.2 < 8.4) && !(7.2 < 3.5 || 1.2 == 2.1 || 2.2 != 2.25))
System.out.print("TRUE");
else
System.out.print("FALSE);
False (*)

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

!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6


True (*)

9. Why are loops useful.


All of the above. (*)

10. In a for loop, the counter is automatically incremented after each loop iteration. True or
False?
False (*)

11. What is a loop?


A set of logic that is repeatedly executed until a certain condition is met. (*)

12. Which of the following best describes a while loop?


A loop that is executed repeatedly until the conditional statement is false. (*)

13. When the for loop condition statement is met the construct is exited. True or false?
False (*)

14. Updating the input of a loop allows you to implement the code with the next element
rather than repeating the code always with the same element. True or false?
True (*)

15. What is one significant difference between a while loop and a do-while loop?
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. (*)
SECTION 6

Section 6 Oracle Java Fundamental Quiz


Section 6 Quiz
(Answer all questions in this section)
1. The following segment of code initializes a 2 dimensional array of primitive data types.
True or false?
double[][] a=new double[4][5];
True (*)

2. 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=new String[2][3]; (*)

3. double array[] = new double[8];


After execution of this statement, which of the following are true?

array.length is 8 (*)

4. What is the output of the following segment of code if the command line arguments are
"apples oranges pears"?

pears (*)

5. What is the output of the following segment of code if the command line arguments are "a b
c d e f g"?

e (*)

6. Which of the following statements is not a valid array declaration

counter int[]; (*)


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

11 (*)

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

777777 (*)

9. The following creates a reference in memory named q that can refer to eight different
doubles via an index. True or false?
double[] q = new double[8];

True (*)

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

666666 (*)

11. Suppose you are writing a program where the user is prompted to the give coordinates
where they believe the princess is inside of the castle.
Your program moves the prince to the coordinates that the user specified. If the princess is not
found at those coordinates, the user is given a clue that helps them guess coordinates closer to the
princess. The user is allowed to enter their new guess of where the princess is.
Assume your program does not take into consideration the possibility that the user may enter
coordinates outside of the castle where the princess could not be. What would be the result of the
user entering coordinates outside of the castle? How could this be handled in your code?
(Choose all correct answers)
An exception would occur. This could be handled by throwing the exception in your code if
the user enters invalid coordinates. When the exception is caught, the prince could be
moved to the coordinate inside the castle that is closest to those that the user specified. (*)

An exception would occur. This could be handled by throwing an exception in your code if
the user enters invalid coordinates. When the exception is caught, the user could be
prompted to enter coordinates within the given range of the castle. (*)
12. Which of the following defines an Exception?
A problem that can be corrected or handled by your code. (*)

13. What do exceptions indicate in Java?


(Choose all correct answers)
A mistake was made in your code. (*)

14. It is possible to throw and catch a second exception inside a catch block of code. True or
false?
True (*)
\
15. What exception message indicates that a variable may have been mispelled somewhere in
the program?
variableName cannot be resolved to a variable (*)

1. What does the interpreter look for when an exception is thrown?


A catch statement in the code. (*)

2. Which of the following could be a reason to throw an exception?


To eliminate exceptions from disrupting your program. (*)

3. A logic error occurs if an unintentional semicolon is placed at the end of a loop initiation
because the interpreter reads this as the only line inside the loop, a line that does nothing.
Everything that follows the semicolon is interpreted as code outside of the loop. True or false?
False (*)

4. Which line of code shows the correct way to throw an exception?


throw new Exception("Array index is out of bounds"); (*)

5. If an exception has already been thrown, what will the interpreter read next in the
program?
Where the program catches the exception. (*)

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

777777 (*)

7. Which of the following declares and initializes a two dimensional array where each element
is a reference type?
String[][] words=new String[10][3]; (*)
8. Which of the following declares and initializes a two dimensional array?
int[][] array={{1,1,1},{1,1,1},{1,1,1}}; (*)

9. The following array declaration is valid:


int[] y = new int[5];
True (*)

10. The following segment of code initializes a 2 dimensional array of primitive data types.
True or false?
double[][] a=new double[4][5];
True (*)

11. Which of the following statements is not a valid array declaration


counter int[]; (*)

12. double array[] = new double[8];

After execution of this statement, which of the following are true?


array.length is 8 (*)

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

642246 (*)

14. The following segment of code prints all five of the command line arguments entered into
this program. True or false?

False (*)

15. 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]);} (*)
SECTION 7

Section 7 Oracle Java Fundamental Quiz


Section 7 Quiz
(Answer all questions in this section)

1. What is encapsulation?
A programming philosophy that promotes protecting data and hiding
implementation in order to preserve the integrity of data and methods. (*)

2. Consider creating a class Square that extends the Rectangle class provided below.
Knowing that a square always has the same width and length, which of the following best
represents a constructor for the Square class?

JAWABAN :

(*)

3. Which of the following demonstrates the correct way to create an applet Battlefield?
public class Battlefield extends Applet{...} (*)

4. What is the Java keyword final used for in a program?


It restricts a class from being extendable and restricts methods from being
overridden. (*)

5. Which of the following are true about abstract methods?


(Choose all correct answers)
They must be overridden in a non-abstract subclass. (*)
They must be declared in an abstract class. (*)
They cannot have a method body. (*)

6. Which of the following would be most beneficial for this scenario?

Joe is a college student who has a tendency to lose his books. Replacing them is getting costly. In
an attempt to get organized, Joe wants to create a program that will store his textbooks in one
group of books, but he wants to make each book type the subject of the book (i.e. MathBook is a
book). How could he store these different subject books into a single array?
Using polymorphism. (*)
7. Consider

public class YourClass{


public YourClass(int i)
{/*code*/}
// more code...}

To instantiate YourClass, what would you write


YourClass y = new YourClass(3); (*)

8. The following code creates an object of type Animal:


Animal a;
False (*)

9. The basic unit of encapsulation in Java is the primitive data type. True or false?
False (*)

10. You can create static class methods inside any Java class. True or false?
True (*)

11. Any instance of the same class can assign a new value to a static variable. True or false?
True (*)

12. Which of the following access modifiers doesn't work with a static variable?
friendly (*)

13. 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(int dol1,int dol2){ if(dol1 > dol2) return dol1; else return dol2;} (*)

14. Which of the following could be a reason to return an object?


The method makes changes to the object and you wish to continue to use the
updated object outside of the method. (*)

15. Which of the following specifies accessibility to variables, methods, and classes?
Access modifiers (*)

1. A final static variable can change at runtime. True or false?


False (*)

2. Static classes can have different access specifiers than the parent class. True or false?
True (*)

3. Static classes can exist as inner classes. True or false?


True (*)
4. Which of the following correctly describes an "is-a" relationship?
A helpful term used to conceptualize the relationships among nodes or leaves in an
inheritance hierarchy. (*)

5. Why are hierarchies useful for inheritance?


They are used to organize the relationship between a superclass and its subclasses.
(*)

6. Which of the following correctly describes the use of the keyword super?
A keyword that allows subclasses to access methods, data, and constructors from
their parent class. (*)

7. What is Polymorphism?
The concept that a variable or reference can hold multiple types of objects. (*)

8. What is the Java keyword final used for in a program?


It restricts a class from being extendable and restricts methods from being
overridden. (*)

9. Identify the correct way to declare an abstract class.


public abstract class ClassName{...} (*)

10. If the return type from a method is boolean then 2.5 is a valid return value. True or false?
False (*)

11. The basic unit of encapsulation in Java is the primitive data type. True or false?
False (*)

12. Consider:

public class MyClass{


public MyClass()
{/*code*/}
// more code...}

To instantiate MyClass, what would you write?


MyClass m = new MyClass(); (*)

13. Which of the following can be used as a parameter?


(Choose all correct answers)
Strings (*)
Integers (*)
Objects (*)
Arrays (*)
14. Which segment of code represents a correct way to define a variable argument method?
String easyArray(String ... elems) {//code} (*)

15. Identify the error(s) in the class below. Choose all that apply

No method named min is defined. (*)

1. Which of the following would be most beneficial for this scenario?

Joe is a college student who has a tendency to lose his books. Replacing them is getting costly. In
an attempt to get organized, Joe wants to create a program that will store his textbooks in one
group of books, but he wants to make each book type the subject of the book (i.e. MathBook is a
book). How could he store these different subject books into a single array?
Using polymorphism. (*)

2. Abstract classes cannot implement interfaces. True or false?


False (*)

3. If Oak extends Tree, it is possible to declare an object such that

Tree grandfatherT = new Oak();

True or false?
True (*)

4. Which segment of code correctly defines a method that contains two objects of class Tree
as parameters?
void bloom(Tree pine, Tree oak) {//code here } (*)

5. 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?


(Choose all correct answers)
Method A can invoke method B twice, each time with a different number of
arguments. (*)
When invoked, method B creates an array to store some or all of the arguments
passed to it from method A. (*)

6. Which of the following is a possible way to overload constructors? Mark for Review
(1) Points

(*)

7. Identify the driver class that correctly initializes employees Jane and Brandon. The
Employee class is below.

public class Employee {


private String name;
private int age;
private double salary;
public Employee(String n, int a, double s) {
name = n;
age = a;
salary = s;
}
//methods for this class would go here
}
public class driver_class {
public static void main(String[] args) {
Employee Jane = new Employee("Jane", 48, 35.00);
Employee Brandon = new Employee("Brandon", 36, 20.00);
}
} (*)

8. What is wrong with the following class declaration?

class Account{
private int number;
private String name;
public Account;
}
The constructor method has no definition. (*)
9. The basic unit of encapsulation in Java is the primitive data type. True or false?
False (*)

10. Static methods can return any object type. True or false?
True (*)

11. Static classes can extend their parent class. True or false?
True (*)

12. Non-final static class variables should be private to prevent changes from other classes.
True or false?
True (*)

13. What is encapsulation?


A programming philosophy that promotes protecting data and hiding
implementation in order to preserve the integrity of data and methods. (*)

14. If a variable in a superclass is private, could it be directly accessed or modified by a


subclass? Why or why not?
No. A private variable can only be modified by the same class with which it is
declared regardless of its inheritance. (*)

15. Which of the following demonstrates the correct way to create an applet Battlefield?
public class Battlefield extends Applet{...} (*)

1. What keyword is used to inherit a superclass?


extends (*)

2. It is possible to extend a class that already exists in Java, such as the Applet class. True or
false?
True (*)

3. Why are hierarchies useful for inheritance?


They are used to organize the relationship between a superclass and its subclasses.
(*)

4. Is there a difference between overriding a method and overloading a method?


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. (*)

5. It is possible to inherit from an abstract class. True or false?


True (*)
6. If Sandal extends Shoe, it is possible to declare an object such that

Sandal s = new Shoe();


False (*)

7. Static classes are designed as thread safe class instances. True or false?
False (*)

8. Static classes can extend any class in their class path. True or false?
True (*)

9. Static classes can extend their parent class. True or false?


True (*)

10. Which segment of code correctly defines a method that contains two objects of class Tree
as parameters?
void bloom(Tree pine, Tree oak) {//code here } (*)

11. Which of the following is the correct way to code a method with a return type an object
Automobile?

Automobile upgrade(Automobile carA){


carA.setTurbo("yes");
return carA;
} (*)

12. Choose the correct implementation of a public access modifier for the method divide.
public int divide(int a, int b) {return a/b;} (*)

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

(*)

14. What value will return for j when the setValue method is called?

11 (*)
15. What is wrong with the following class declaration?

There is nothing wrong. (*)

1. Which of the following keywords are used to access the instance variables of an object
from within the class code for that object?
this (*)

2. The following code creates an object of type Animal:


Animal a;
False (*)

3. What is wrong with the following class declaration?

class Account{
private int number;
private String name;
public Account;
}
The constructor method has no definition. (*)

4. Where should the constructor for a superclass be called?


The first line of the constructor in the subclass. (*)

5. 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 (*)

6. Which of the following correctly describes the use of the keyword super?
A keyword that allows subclasses to access methods, data, and constructors from
their parent class. (*)

7. Abstract classes can be instantiated. True or false?


False (*)

8. Which of the following is a goal of the object model?


(Choose all correct answers)
Providing modular code that can be reused by other programs or classes. (*)
Protecting information and limiting other classes' ability to change or corrupt data.
(*)
Concealing implementation. (*)
Data abstraction. (*)
9. Abstract classes cannot implement interfaces. True or false?
False (*)

10. There is only one copy a static class variable in the JVM. True or false?
True (*)

11. A final static variable can change at runtime. True or false?


False (*)

12. Which of the following access modifiers doesn't work with a static variable?
friendly (*)

13. How is it possible for overloading to work?


Java Virtual Machine searches until it finds a constructor name and argument type
match. (*)

14. Which of the following could be a reason to return an object?


The method makes changes to the object and you wish to continue to use the
updated object outside of the method. (*)

15. Identify the error(s) in the class below. Choose all that apply

No method named min is defined. (*)

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.
private (*)
2. Identify the error(s) in the class below. Choose all that apply

No method named min is defined. (*)

3. Which segment of code represents a correct way to call a variable argument method
counter that takes in integers as its variable argument parameter?
counter(1, 5, 8, 17, 11000005); (*)

4. The return value of a method can only be a primitive type and not an object. True or
false? False (*)

5. All objects, in Java, are created using int. True or false?


False (*)

6. Which of the following is true?


A class always has a constructor (possibly automatically supplied by the java
compiler). (*)

7. If an abstract class does not have implemented constructors or methods, it should be


implemented as an interface instead. True or false?
True (*)

8. 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?
Dynamic Method Dispatch (*)

9. What is the Java keyword final used for in a program?


It restricts a class from being extendable and restricts methods from being
overridden. (*)

10. Which of the following correctly defines a superclass (or parent class)?
A class that passes down its methods to more specialized classes. (*)

11. It is possible for a subclass to be a superclass. True or false?


True (*)
12. Which of the following correctly describes an "is-a" relationship?
A helpful term used to conceptualize the relationships among nodes or leaves in an
inheritance hierarchy. (*)

13. Static methods can write to instance variables. True or false?


False (*)

14. Static classes can't return instances of the parent class when the parent class uses a private
constructor. True or false?
False (*)

15. Static classes can have different access specifiers than the parent class. True or false?
True (*)

1. According to the following class declaration, runSpeed can be modified in class Cat. True
or false

public class Tiger extends Cat{


public int runSpeed;
}
True
False (*)

2. If a variable in a superclass is private, could it be directly accessed or modified by a


subclass? Why or why not?
No. A private variable can only be modified by the same class with which it is
declared regardless of its inheritance. (*)

3. It is possible to extend a class that already exists in Java, such as the Applet class. True or
false? True (*)

4. If the return type from a method is boolean then 2.5 is a valid return value. True or false?
False (*)

5. The following statement compiles and executes. What do you know for certain?

tree.grows(numFeet);
grows must be the name of a method. (*)

6. A constructor must have the same name as the class where it is declared. True or false?
True (*)

7. If a class is immutable then it must be abstract. True or false?


False (*)
8. Which of the following is a goal of the object model?

(Choose all correct answers)


Data abstraction. (*)
Protecting information and limiting other classes' ability to change or corrupt data.
(*)
Providing modular code that can be reused by other programs or classes. (*)
Concealing implementation. (*)

9. Identify the step (s) in creating a Triangle Applet that displays two triangles.
(Choose all correct answers)
Draw the triangle using the inherited fillPolygon method. (*)
Draw the 2nd triangle using the inherited fillPolygon method. (*)
Extend Applet class to inherit all methods including paint. (*)
Override the paint method to include the triangles. (*)
Run and compile your code. (*)

10. How is it possible for overloading to work?


Java Virtual Machine searches until it finds a constructor name and argument type
match. (*)

11. 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? Mark for Review
(1) Points
public (*)

12. It is possible to overload a method that is not a constructor. True or False?


True (*)

13. A static variable is always publicly available. True or false?


False (*)

14. Static methods can read instance variables. True or false?


False (*)

15. Static classes can exist as stand alone classes. True or false?
False (*)

Das könnte Ihnen auch gefallen