Show Nội dung chính Show
1. What is true about the code below: Car car1=new Car(); (Choose all correct answers) There are no more Car objects in memory. There is a Car object that car1 referenced that is now slated for removal by the garbage collector. There is a Car object that car2 referenced that is now slated for removal by the garbage collector. The reference car2 points to an exact copy of the Car Object that car1 references. (*) The references car1 and car2 are pointing to two Car Objects in memory. [Incorrect] Incorrect. Refer to Section 7 Lesson 1. True False (*) [Incorrect] Incorrect. Refer to Section 7 Lesson 1. 3. Java's garbage collection is when all references to an object are gone, the memory used by the object is automatically reclaimed. True
or false? Mark for Review True (*) False [Correct] Correct 4. If you inherit a class, you do not inherit the class' constructors. True or false? Mark for Review True (*) False [Correct] Correct 5. 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? Mark for Review (*) None of the above. [Incorrect]
Incorrect. Refer to Section 7 Lesson 4. A keyword that allows or restricts access to data and methods. A programming philosophy that promotes simpler, more efficient coding by using exiting 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 structure that categorizes and organizes relationships among ideas, concepts of things with the most general at the top and the most specific at the bottom. [Incorrect] Incorrect. Refer to Section 7 Lesson 4. 7.
Abstract classes can be instantiated. True or false? Mark for Review True False (*) [Incorrect] Incorrect. Refer to Section 7 Lesson 5. 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? Mark
for Review Abstract classes Polymorphism Dynamic Method Dispatch (*) Inheritance [Incorrect] Incorrect. Refer to Section 7 Lesson 5. 9. Would this code be correct if a Dog is a HousePet? Why or Why not? HousePet Scooby = new Dog(); Mark for Review Yes, because polymorphism allows this since Dog is a subclass of HousePet. (*) Yes, because it is an abstract class. No, because ref must be declared either a HousePet or a Dog, but not both. Maybe. There is no way to tell without seeing the methods for Dog and the methods for HousePet. [Correct] Correct 10. Static methods can return any object type. True or false? Mark for Review True (*) False [Correct] Correct True False (*) [Incorrect] Incorrect. Refer to Section 7 Lesson 3. 12. Static methods can read instance variables. True or false? Mark for Review True False (*) [Incorrect] Incorrect. Refer to Section 7 Lesson 3. 13. It is possible
to overload a method that is not a constructor. True or False? Mark for Review True (*) False [Correct] Correct 14. 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 public (*) protected private default All of the above [Correct] Correct 15. Which
segment of code correctly defines a method that contains two objects of class Tree as parameters? Mark for Review void bloom(Tree pine, Tree oak) {//code here } (*) Tree bloom (pine, oak) {//code here } void bloom, Tree pine, Tree oak {//code here } None of the above, objects cannot be passed as parameters. [Correct] Correct
!=,=,== &,|,= &&, ||, ! (*) &&,!=,= [Incorrect] Incorrect. Refer to Section 5 Lesson 1.
2. Which of the following correctly matches the switch statement keyword to its function? Mark for Review (Choose all correct answers) switch: identifies what element will be compared to the element of the case statements to find a possible match (*) if: records the user's input and sends it to the case statements to find a possible match case: signals what code is executed if the user input matches the specified element (*) switch: tells the compiler the value to compare the input against default: signals what code to execute if the input does not match any of the cases (*) [Incorrect] Incorrect. Refer to Section 5 Lesson 1. 3. This keyword is used to instruct specific code when the input for a switch statement that does not match any of the cases. Mark for Review switch case break default (*) None of the above [Incorrect] Incorrect. Refer to Section 5 Lesson 1. 4. How would you use the ternary operator to rewrite this if statement? if
(balance < 500) fee = ( balance >= 5) ? 0 : 10; fee = ( balance > 5) ? 10 : 0; fee= ( balance < 500) ? 10 : 0; (*) fee = ( balance < 500) ? 0 : 10; fee = ( balance >= 500) ? 10 : 0; [Incorrect] Incorrect. Refer to Section 5 Lesson 1. 5. In Java, each case seqment of a switch statement requires the keyword break to avoid "falling through". Mark for Review True (*) False [Correct] Correct if
((5.1 > 4.3 && 6.2 < 8.4) && !(7.2 < 3.5 || 1.2 == 2.1 || 2.2 != 2.25)) True False (*) [Incorrect] Incorrect. Refer to Section 5 Lesson 1. 7. Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement? Mark for Review Example A (*) Example B [Correct] Correct 8. The following prints Yes on the screen. True or false? Mark for Review True False (*) [Incorrect] Incorrect. Refer to Section 5 Lesson 1.
9. How many times will the following loop be executed? int count = 17; 3; 27; 8 (*) 5; 27; 8 4; 8; 27 5; 30; 5 3; 9; 11 [Correct] Correct 10. A counter used in a for loop cannot be initialized within the For loop header. True or false? Mark for Review True False (*) [Incorrect] Incorrect. Refer to
Section 5 Lesson 2. True (*) False [Correct] Correct 12. In a for loop the counter is not automatically incremented after each
loop iteration. Code must be written to increment the counter. True or false? Mark for Review True (*) False [Correct] Correct 13. For both the if-else construct and the for loop, it is true to say that when the condition statement is met, the construct is exited. True or False? Mark for Review True False (*) [Incorrect] Incorrect. Refer to Section 5 Lesson 2. 14. In the code fragment below, the syntax for the for loop's initialization is correct. True or false? public class ForLoop { Mark for Review
True False (*) [Incorrect] Incorrect. Refer to Section 5 Lesson 2. 15. Why are loops useful? Mark for Review They save programmers from having to rewrite code. They allow for repeating code a variable number of times. They allow for repeating code until a certain argument is met. All of the above. (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2. 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? 3. Which of the following could be a reason to need to pass an object into a method?
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? 5. Cameron wishes to write a method that takes in two objects and returns the one with the greatest value. Is this possible? 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. 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? 8. What type(s) would work for a variable argument method? 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? (*) Quiz 2 Sectiunea 7 1. Static variables can't use which of the following specifiers? 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? 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 (*) 7. You can use an inner static class to return an instance of its outer class container. True or false? True (*)
False 10. A non-linear recursive method can call how many
copies of itself? Quiz 3 Sectiunea 7 1. What is a UML? 2. What does it mean to inherit a class?
3. Which of the following correctly defines a superclass (or parent class)? 4. Which of the following correctly defines a subclass (or child class)?
5. Methods are generally declared as public so other classes may use them. True or false? 7. Which of the following correctly describes the use of the
keyword super? 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? 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? 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? 4. Which of the following is a goal of the object model? 5. If Sandal extends Shoe, it is possible to declare an object such that
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? 7. Which of the following are true about an abstract class? 1. What is a loop? 2. It is necessary to end all loops at some point in your Java program. True or false? 3. Which of the
following are types of loops in Java? 6. What is the function of the word
"break" in Java? Quiz 2 Sectiunea 5 1. Which of the following creates a class named Diver with one constructor, and 2 instance variables maxDepth and certified? 3. Which of the following creates a Object from the Animal class listed below? • Animal dog=new Animal(); 4. Complete the sentence. A constructor... 5. The following code creates an Object of type Animal: 6. Which of the following creates an object from the Car class listed below? • Car c = new Car(3000, "Toyota"); (*) 7. What is wrong with the following class declaration? 8. Which of the following is true? 9.What value will be returned when the setValue method is called? • 35 • 36 • 37 (*) • 38 10. The return value of a method can only be a primitive type and not an object. True or false? 12.Which of the following calls the method moveUp in the class
below: 13. A class can have multiple constructors. True or false? True (*) False 14. The constructor of a class has the same name as the class. True or false? True (*) False 15. Which of the following adds a constructor to the class below? (*) 17. Consider: public class MyClass{ public MyClass(){/*code*/} // more code...} 18. Which of the following may be part of a class definition?
19. What is garbage collection in the context of Java? 20. Which of the following keywords are used to access the instance variables of an object from within the class code for that object? 21. Which constructor code populates the instance variables of the class correctly? (*) 1. Which of the following statements is a valid array declaration? 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? 4. Which of the following
declares and initializes a two dimensional array? 5. Which of the following declares and initializes a one dimensional array named words of size 10 so that all entries can be Strings? 6. What is the output of the following segment of code? 7. What is the output of the following segment of code? 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? 10. Which of the following statements print every element of the one dimensional array prices to the screen? 11. What is the output of the following segment of code? 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"? 15. What is the output of the following segment of code if the command line arguments are "apples oranges pears"? 16. What will be the content of array variable table after executing the following code? • 0 0 0 17.What is the output of the following segment of code? 18. After execution of the following statement, which of the following are true? 19. The following array declaration is valid. True or false? int x[] = int[10]; True False (*) Quiz 2 Sectiunea 6 1. Consider the following code snippet. What is printed? 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? 5. Suppose that s1 and s2 are two strings. Which of the statements or expressions are
valid? • PoliiPolii (*) 7. What will the following code segment output? • ""\\" 10. Which of the following creates a String named string? 11. Given the code, which of the following would equate to true? • True • False (*) 15. Given the code below, which of the following
calls are valid? String s = new String("abc"); • 55555 18. Consider the following code snippet. What is printed? • 55555 19.How would you use the ternary operator to rewrite this if statement? 20. How would you use the
ternary operator to rewrite this if statement? Quiz 3 Sectiunea 6
1. Which of the following would give you an array index out of bounds exception? 2. What exception message indicates that a variable may have been mispelled somewhere in the program? 3. Which of the following defines an Exception? 4. What
do exceptions indicate in Java? 5. Which line of code shows the correct way to throw
an exception? 6. What does the interpreter look for when an exception is thrown? 7. Which of the following would be a correct way to handle an index out of bounds exception? 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? 1. The ______________ is the location into which you will store and save your files. Mark for
Review 2. Multiple windows are used when more than one file is open in the edit area. True or
False? Mark for Review 3. A workspace can have one or more stored projects. True or false? Mark for Review 4. Tabs are used when more than one file is open in the edit area. True or False? Mark for Review 5.
A _______________ is used to organize Java related files. Mark for Review Section 4 6. Which of the two diagrams below illustrate the general form of a Java program? Example A Example B (*) 7. The
following defines a package keyword: Mark for Review 8. The following code is an example of a correct initialization statement: 9. Suppose that str1 and str2 are two strings. Which
of the statements or expressions are valid? Mark for Review 10.
Which of the following creates a String named string? Mark for Review Section 4 11. Which of the following creates a String reference named s and instantiates it? Mark for Review 12. Which of the following creates a String reference named str and instantiates
it? Mark for Review 13. Which line of code does not assign
3.5 to the variable x? Mark for Review 14. Which line of Java code assigns the value of 5
raised to the power of 8 to a? Mark for Review 15. What two values can a boolean variable have? Mark for Review Section 5 16. The following prints Yes on the screen. True or false? 17. How would you use the ternary operator to rewrite this if statement? if (gender == "female") System.out.print("Ms."); 18. Which of the following expressions will evaluate to true when x and y are boolean variables with opposite values? I. (x || y) && !(x && y) 19. Why are loops useful? Mark for Review 20. A counter used in a for loop cannot be initialized within the For loop header. True or false? Mark for Review Section
5 21. Which of the following best describes a while loop? Mark for Review Section 6 22. 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? Mark for Review 23. What does it mean to catch an exception? Mark for Review 24. What do exceptions indicate in Java? Mark for Review 25. Which of the following would be a correct way to handle an index out of bounds exception? Mark for Review Section 6 26. The following creates a reference in memory named k that can refer to six different integers via an index. True or false? int k[]= int[6]; Mark for Review 27. What is the output of the following segment of code? int num[]={9,8,7,6,5,4,3,2,1}; 28. What is the output of the following segment of code? int array[][] = {{1,2,3},{3,2,1}}; 29. What is the
output of the following segment of code? Section
7 Section 7 31. Which of the following is the definition for a variable argument method? Mark for Review 32. 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? Mark for Review 33. What type(s) would work for a variable argument method? Mark for Review 34. 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. Mark for Review 35. Methods are generally declared as public so other classes may use them. True or false? Mark for Review Section 7 36. Which of the following correctly describes an "is-a" relationship? Mark for Review 37. Which of the following demonstrates the correct way to create an applet Battlefield? Mark for Review 38. What is encapsulation? Mark for Review 39. The following code creates an object of type Horse: 40. Which of the
following keywords are used to access the instance variables of an object from within the class code for that object? Mark for Review Section
7 41. Which constructor code populates the instance variables of the class correctly? Mark for Review (*) 42. Which of the following calls the method calculate correctly? 43. Which of the following creates a method that returns a boolean
value? Mark for Review (*) None of the above. 44. A constructor must have the same name as the class where it is declared. True or false? Mark for Review 45. Which of the following is a goal of the object model? Mark for Review Section 7 46. Which of the following can be declared final? Mark for Review 47. If we override the toString() method with the code below, what would be the result of printing? Mark for Review 48.
You can use an inner static class to return an instance of its outer class container. True or false? Mark for Review 49. You can return an instance of a private class through a static method of a different class. True or false?
Mark for Review 50. You can assign new values to static variables by prefacing them with the this keyword and a dot or period. True or false? Mark for Review 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? Mark for Review 3. double array[] = new double[8]; 4. What is the output of the following segment of code if the command line arguments are "apples oranges pears"? Mark for
Review 5. What is the output of the following segment of code if the command line arguments are "a b c d e f g"? Mark for Review 6. Which of the following statements is not a valid array declaration? Mark for Review 7. What is the output of the following segment of code? Mark for Review 8. What is the output of the following segment of code? Mark for Review 9. The following creates a reference in memory named q that can refer
to eight different doubles via an index. True or false? 10. What is the output of the following segment of code? Mark for Review 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. 12. Which of the following defines an Exception? Mark for
Review 13. What do exceptions indicate in Java? Mark for Review 14. It is possible to throw and catch a second exception inside a catch block of code. True or false? Mark for Review 15. What exception message indicates that a variable may have been mispelled somewhere in the program? Mark for
Review 1. What does the interpreter look for when an exception is thrown? Mark for Review 2. Which of the following could be a reason to throw an exception?
Mark for Review 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? Mark for Review 4. Which line of code shows the correct way to throw an exception? Mark for Review 5. If an exception has already been thrown, what will the interpreter read next in the program? Mark for Review Section 6 Quiz
Mark for Review 7. Which of the following declares and initializes a two dimensional array where each element is a reference type? Mark for Review 8. Which of the following declares and initializes a two dimensional
array? Mark for Review 9. The following array declaration is valid: 10. The following segment of code initializes a 2 dimensional array of primitive data types. True or
false? 11. Which of the following statements is not a valid array declaration? Mark for Review 12. double array[] = new double[8]; After execution of this statement, which of the following are true? Mark for Review 13. What is the output of the following segment of code? Mark for
Review 14. The following segment of code prints all five of the command line arguments entered into this program. True or false? Mark for Review 15. Which of the following statements print every element of the one dimensional array prices to the screen? Mark for Review 1. What are Java's simple types? boolean, byte, char, double, float, int, long, and short (*) 2. Which of the following are relational operators in Java? (Choose all correct answers) < (*) 3. What is the output of the following lines of code? 4. A local variable has precedence over a global variable in a Java method. True or false? True (*) False 5. What does the following program output? total cost: + 40 6. What is the result when the following code segment is compiled and executed? int x = 22, y = 10; Syntax error "sqrt(double) in java.lang.Math cannot be applied to int"
!(3<4&&6>6||6<=6&&7-2==6) True False (*) 9. Which of the two diagrams below illustrate the general form of a Java program? Example A Example B (*) 10. In a For loop the counter is not automatically incremented after each loop iteration. Code must be written to increment the counter. True or false? True (*) False 11.
When the For loop condition statement is met the construct is exited. True or false? 12. You can return to the Eclipse Welcome Page by choosing Welcome from what menu? File
13. In Eclipse, when you run a Java Application, where may the results display? Editor Window 14. A combination of views and editors are referred to as _______________. A workspace 15. What are the Eclipse Editor Area and Views used for?(Choose all correct answers) To modify elements. (*) int n = 13; 1.75, 13
17. 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? 18. One advantage to using a WHILE loop over a FOR loop is that a WHILE loop always has a counter. True or false? True False (*) 19. Which of the following could be a reason to use a switch statement in a Java program? 20. In Java, an instance field referenced using the this keyword generates a compilation error. True or false? 21. Consider public class YourClass{ public YourClass(int i){/*code*/} // more code...} To instantiate YourClass, what would you write? 22. A constructor must have the same name as the class it is declared within. True or false? 23. Which of the following keywords are used to control access to the member of a class? default (*) All of the above. None of the above 25. The following code creates an Object of type Horse. True or false? 26. What operator do you use to call an object's constructor method and create a new object? + 27. Which of the following declares a one dimensional array name scores of type int that can hold 14 values? int scores; 28. Which of the following statements is not a valid array declaration? 29. What is the output of the following segment of code if the command line arguments are "a b c d e f"? 1 30. Which of the following declares a one dimensional array named names of size 8 so that all entries can be Strings? String names=new String[8]; 31. What will the following code segment output? String s="\\\\\ "\\\\\" 32. Consider the following code snippet. What is printed? Mark for Review 88888 (*) 33. Given the code String s1 = "abcdef"; Which of the following would equate to false? 34. How would you use the ternary operator to rewrite this if statement? if (balance < 500) fee
= ( balance < 500) ? 0 : 10; 35. If an exception is thrown by a method, where can the catch for the exception be? There does not need to be a catch in this situation. 36. Choose the best response to this statement: An error can be handled by throwing it and catching it just like an exception. 37. Which of the following could be a reason to throw an exception?
To eliminate exceptions from disrupting your program. (*) 38. Suppose you misspell a method name when you call it in your program. Which of the following explains why this gives you an exception? Because the parameters of the method were not met. 39. Which of the following is the correct way to call an overriden method needOil() of a super class Robot in a subclass SqueakyRobot? Robot.needOil(SqueakyRobot); 40. Why are hierarchies useful for inheritance? They keep track of where you are in your program. 41. It is possible for a subclass to be a superclass. True or false? True (*) False 42. Static methods can write to instance variables. True or false? 43. Static classes are designed as thread safe
class instances. True or false? 44. Public static variables can't have their value reset by other classes. True or false? 45. Choose the correct implementation of a public access modifier for the method divide.
46. Which of the following specifies accessibility to variables, methods, and classes? 47. 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(String a, int b);
48. Which of the following can be declared final? 49. 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?
By ignoring the subject type and initializing all the book as objects of type Book. 50. What is Polymorphism?
A way of redefining methods with the same return type and parameters. Quiz 1 Sectiunea 6 1. Which of the following statements is a valid array declaration? 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?
4. Which of the following declares and initializes a two dimensional array? 5. Which of the following declares and initializes a one dimensional array named words of size 10 so that all entries can be
Strings? 6. What is the output of the following segment of code? 7. What is the
output of the following segment of code? 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? 10. Which of the following statements print every element of the one dimensional array prices to the screen? 11. What is the output of the following segment of code? 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"? 15. What is the output of the following segment of code if the command line arguments are "apples oranges pears"? 16. What will be the content of array variable table after executing the following code? • 0 0 0 17.What is the output of the following segment of code? 18. After execution of the following statement, which of the following are true? 19. The following array declaration is valid. True or false? int x[] = int[10]; True False (*) Quiz 2 Sectiunea 6 1. Consider the following code snippet. What is printed? 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? 5. Suppose that s1 and s2 are two strings. Which of the statements or expressions are
valid? • PoliiPolii (*) 7. What will the following code segment output? • ""\\" 10. Which of the following creates a String named string? 11. Given the code, which of the following would equate to true? • True • False (*) 15. Given the code below, which of the following
calls are valid? String s = new String("abc"); • 55555 18. Consider the following code snippet. What is printed? • 55555 19.How would you use the ternary operator to rewrite this if statement? 20. How would you use the
ternary operator to rewrite this if statement? Quiz 3 Sectiunea 6
1. Which of the following would give you an array index out of bounds exception? 2. What exception message indicates that a variable may have been mispelled somewhere in the program? 3. Which of the following defines an Exception? 4. What
do exceptions indicate in Java? 5. Which line of code shows the correct way to throw
an exception? 6. What does the interpreter look for when an exception is thrown? 7. Which of the following would be a correct way to handle an index out of bounds exception? 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? 1. Select the statement that declares a number of type double and initializes it to 6 times 10 to the 5th power.
16. What should replace the comment "//your answer here" in the code below if the code is meant to take no action when i % 2 is
0 (in other words when i is even)? ""\ \ " Incorrect. Refer to Section 6 Lesson 2. 1. What is encapsulation? Mark for Review 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? Mark for Review 3. Which of the following demonstrates the correct way to create
an applet Battlefield? Mark for Review 4. What is the Java keyword final used for in a program? Mark for Review 5. Which of the following are
true about abstract methods? Mark for Review 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? Mark for Review 7. Consider public class
YourClass{ To instantiate YourClass, what would you write? Mark for Review 8. The following code creates an object of type Animal: 9.
The basic unit of encapsulation in Java is the primitive data type. True or false? Mark for Review 10. You can create static class methods inside any Java class. True or false? Mark for Review 11. Any instance of the same class can assign a new value to a static variable. True or false? Mark for Review 12. Which of the following access
modifiers doesn't work with a static variable? Mark for Review 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? Mark for Review 14.
Which of the following could be a reason to return an object? Mark for Review 15. Which of the following specifies accessibility to variables, methods, and classes? Mark for Review Which of the following is a valid array declaration?(1), (2), and (4) are legal array declarations. With an array declaration, you can place the brackets to the right or left of the identifier. Option A looks strange, but it's perfectly legal to split the brackets in a multidimensional array, and place them on both sides of the identifier. Which among the following statements are valid array declarations in Java?221. Which of the following statements is/are valid array declarations? ... Answers.. Which of the following is not a valid array declaration?Which of these is an incorrect array declaration? Explanation: Operator new must be succeeded by array type and array size. Which of the following statements about array declaration is false?This statement is false, because it designates the second element of the array. 3. It is necessary to initialize the array at the time of declaration. This statement is false. ... 50001.. |