download serba-serbi aneka konten

Breaking

Selasa, 22 Januari 2019

Answers Oracle Academy Java Fundamental Part 3



1. Given the code:
String s = new String("abc");
Which of the following statements will change the length of s to the largest length? Mark for Review  (1) Points  s.trim() 
s.replace("a", "aa") 
s.substring(2) 
s.toUpperCase() 
None of the above will change the length of s. (*) 
 Correct
2. Suppose that str1 and str2 are two strings. Which of the statements or expressions are valid? Mark for Review  (1) Points  String str3 = str1 - str2; 
str1 += str2; (*) 
str1 >= str2 
Str1 -= str2; 
 Correct  3. Which of the following creates a String named Char? Mark for Review  (1) Points  char string; 
String Char; (*) 
char Char; 
char char; 
String char; 
 Correct  4. What will the following code segment output?
String s="\\\n\"\n\\\n\""; System.out.println(s); Mark for Review  (1) Points  \" \" 
""\ "" \ "" 
\ " \ " (*)
 
" \ " \ " " 
 Incorrect. Refer to Section 4 Lesson 4.  5. Consider the following code snippet 
String forest = new String("Black");  System.out.println(forest.length()); 
What is printed? Mark for Review  (1) Points  5 (*) 


Black 
Forest 
 Incorrect. Refer to Section 4 Lesson 4.  6. Given the following declaration, which line of Java code properly casts one type into another without data loss? 
int i=3,j=4; double y=2.54; Mark for Review  (1) Points
int x=(double)2.54; 
double x=i/j; 
double x=(double)(i/j); 
double x= double i/j; 
double x=(double)i/j; (*)
   Incorrect. Refer to Section 4 Lesson 3.  7. What two values can a boolean variable have? Mark for Review  (1) Points  Numbers and characters 
True and false (*) 
Relational and logic operators 
Arithmetic and logic operators 
Integers and floating point types 
 Incorrect. Refer to Section 4 Lesson 3.  8. Which of the following defines a driver class? Mark for Review  (1) Points  Contains a main method and other static methods. (*) 
Contains classes that define objects. 
Contains a main method, a package, static methods, and classes that define objects. 
None of the above. 
 Incorrect. Refer to Section 4 Lesson 2.  9. Which of the following defines an object class? Mark for Review  (1) Points  Contains a main method and other static methods. 
Contains classes that define objects. (*) 
Contains a main method, a package, static methods, and classes that define objects. 
None of the above. 
 Incorrect. Refer to Section 4 Lesson 2.  10. In the image below, identify the components. 

Mark for Review  (1) Points  A-Main Method, B-Class, C-Package 
A-Class, B-MainMethod, C-Package 
A-Package, B-Main Method, C-Class (*) 
None of the above 
 Incorrect. Refer to Section 4 Lesson 1.  11. You can return to the Eclipse Welcome Page by choosing Welcome from what menu? Mark for Review  (1) Points  File 
Edit 
Help (*) 
Close 
 Incorrect. Refer to Section 4 Lesson 1.
12. Multiple windows are used when more than one file is open in the edit area. True or False? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 4 Lesson 1.  13. What is the purpose of the Eclipse Editor Area and Views? Mark for Review  (1) Points (Choose all correct answers)   To modify elements. (*) 
To navigate a hierarchy of information. (*) 
To choose the file system location to delete a file. 
 Incorrect. Refer to Section 4 Lesson 1.  14. In Eclipse, when you run a Java Application, the results are displayed in a new window. True or False? Mark for Review  (1) Points  True 
False (*) 
 Correct
Section 5 (Answer all questions in this section) 15. 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)?
for(int i = 0; i < 10; i++){<br> if(i%2 == 0) //your answer here else k+=3; } Mark for Review  (1) Points  continue; (*) 
break; 
return;
 k+=1; 
 Incorrect. Refer to Section 5 Lesson 2.  16. 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? Mark for Review  (1) Points  True (*) 
False 
 Incorrect. Refer to Section 5 Lesson 2.  17. When the for loop condition statement is met the construct is exited. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 5 Lesson 2.  18. Consider that a Scanner has been initialized such that:
Scanner in = new Scanner(System.in);
Which of the following lines of code reads in the user's input and sets it equal to a new String called input? Mark for Review  (1) Points  String input = in.next(); (*) 
String input = in.close(); 
String input = new String in.next(); 
String input = in.nextInt(); 
 Incorrect. Refer to Section 5 Lesson 1.  19. How would you use the ternary operator to rewrite this if statement? 
if (gender == "female") System.out.print("Ms."); else System.out.print("Mr."); Mark for Review  (1) Points  System.out.print( (gender == "female") ? "Mr." : "Ms." );
 
System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*) 
(gender == "female") ? "Mr." : "Ms." ; 
(gender == "female") ? "Ms." : "Mr." ; 
 Correct  20. switch statements work on all input types including, but not limited to, int, char, and String. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 5 Lesson 1.  21. It is possible to throw and catch a second exception inside a catch block of code. True or false? Mark for Review  (1) Points  True (*) 
False 
 Correct  22. The following segment of code initializes a 2 dimensional array of primitive data types. True or false?
double[][] a=new double[4][5]; Mark for Review  (1) Points  True (*) 
False 
 Incorrect. Refer to Section 6 Lesson 1.  23. What will be the content of the array variable table after executing the following code? 

Mark for Review  (1) Points  1 1 1 0 1 1 0 0 1 
1 0 0 0 1 0 0 0 1 
1 0 0 1 1 0 1 1 1 (*) 
0 0 1 0 1 0 1 0 0 
 Incorrect. Refer to Section 6 Lesson 1.  24. What is the output of the following segment of code? 
Mark for Review  (1) Points  321123 
642 
642246 (*) 
312213 
This code doesn't compile.

 Correct  25. What is the output of the following segment of code? 
int array[][] = {{1,2,3},{3,2,1}};  for(int i=0;i<2;i++)  for(int j=0;j<3;j++)  System.out.print(2*array[1][1]); Mark for Review  (1) Points  444444 (*) 
123321 
246642 
222222 
This code doesn't compile. 
 Incorrect. Refer to Section 6 Lesson 1.  26. Of the options below, what is the fastest run-time? Mark for Review  (1) Points

n^2 
lg(n) (*) 
n*lg(n) 
 Incorrect. Refer to Section 6 Lesson 2.  27. Which of the following is the correct lexicographical order for the conents of the int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review  (1) Points  {71, 1, 3, 28,29, 50, 22, 83, 1, 17} 
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1} 
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83}
 
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3} 
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83} (*) 
 Incorrect. Refer to Section 6 Lesson 2.  28. Selection sort is efficient for large arrays. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 6 Lesson 2.  29. Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list. True or false? Mark for Review  (1) Points  True (*) 
False 
 Correct
Section 7 (Answer all questions in this section) 30. Choose the correct implementation of a public access modifier for the method divide. Mark for Review  (1) Points  divide(int a, int b, public) {return a/b;} 
public divide(int a, int b) {return a/b;} (*) 
divide(int a, int b) {public return a/b;} 
divide(public int a, public int b) {return a/b;} 
 Incorrect. Refer to Section 7 Lesson 2.  31. Which of the following could be a reason to return an object? Mark for Review  (1) Points  Because you wish to be able to use that object inside of the method. 
It has faster performance than returning a primitive type. 
The method makes changes to the object and you wish to continue to use the updated object
outside of the method. (*) 
None of the above. It is not possible to return an object. 
 Incorrect. Refer to Section 7 Lesson 2.  32. Which of the following is the correct way to code a method with a return type an object Automobile? Mark for Review  (1) Points  Automobile upgrade(String carA){  carA="Turbo";  return carA;} 
Automobile upgrade(Automobile carA){  carA.setTurbo("yes");  return carA;} (*) 
String upgrade(String carA){  carA="Turbo";  return carA;} 
upgrade(Automobile carA) Automobile{  carA.setTurbo("yes");  return carA;} 
None of the above. It is not possible to return an object. 
 Correct  33. It is possible to overload a method that is not a constructor. True or False? Mark for Review  (1) Points  True (*) 
False 
 Correct  34. Identify the error(s) in the class below. Choose all that apply.

Mark for Review  (1) Points (Choose all correct answers)   No method named min is defined. (*) 
Two methods cannot have the same name. 
The parameters must be the same for all methods with the same name. 
Private cannot be used as an access modifier. 
Final cannot be used as an access modifier. 
 Incorrect. Refer to Section 7 Lesson 2.  35. What is the Java Applet? Mark for Review  (1) Points (Choose all correct answers)   It is the virtual machine that translates Java code into a representation that the computer can understand. 
A web-based Java program that is embedded into a web browser. (*) 
A graphic visual included in Java. (*)
 There is no such thing as a Java Applet. 
 Correct  36. Why are hierarchies useful for inheritance? Mark for Review  (1) Points  They keep track of where you are in your program. 
They restrict a superclass to only have one subclass. 
They organize constructors and methods in a simplified fashion. 
They are used to organize the relationship between a superclass and its subclasses. (*) 
 Correct  37. Which of the following correctly describes an "is-a" relationship? Mark for Review  (1) Points  A helpful term used to conceptualize the relationships among nodes or leaves in an inheritance hierarchy. (*) 
A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications. 
It restricts access to a specified segment of code. 
A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. 
 Incorrect. Refer to Section 7 Lesson 4.  38. Why is it not possible to extend more than one class at a time in an inheritance hierarchy chain? Mark for Review  (1) Points  It is not necessary considering all public content is passed from super class to subclass and further to their subclass and that subclass' subclass and so on. (*) 
Because the computer cannot handle code that complex. 
To prevent confusion for the programmer. 
It is possible to extend more than one class at a time. 
 Correct
39. The following code creates an object of type Horse: Whale a=new Whale(); Mark for Review  (1) Points  True 
False (*) 
 Correct  40. A constructor is used to create objects. True or false? Mark for Review  (1) Points  True (*) 
False 
 Correct  41. The constructor method must always have at least one parameter. True or false? Mark for Review  (1) Points  True 
False (*) 
 Correct  42. The basic unit of encapsulation in Java is the primitive data type. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 7 Lesson 1.  43. What is true about the code below:
Car car1=new Car(); Car car2=new Car(); car2=car1; Mark for Review  (1) Points (Choose all correct answers)   The references car1 and car2 are pointing to two Car Objects in memory. 
The reference car2 points to an exact copy of the Car Object that car1 references. (*)
 
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. (*) 
 Incorrect. Refer to Section 7 Lesson 1.  44. The following code creates an object of type Animal. True or false? 
Animal a=new Animal(); Mark for Review  (1) Points  True (*) 
False 
 Correct  45. If an abstract class does not have implemented constructors or methods, it should be implemented as an interface instead. True or false? Mark for Review  (1) Points  True (*) 
False 
 Incorrect. Refer to Section 7 Lesson 5.  46. Abstract class cannot extend another abstract class. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 7 Lesson 5.  47. Which of the following can be declared final? Mark for Review  (1) Points  Classes 
Methods 
Local variables
 Method parameters 
All of the above (*) 
 Correct  48. A non-linear recursive method calls how many copies of itself in the recursive case? Mark for Review  (1) Points  0 

2 or more (*) 
 Correct  49. Static classes can extend their parent class. True or false? Mark for Review  (1) Points  True (*) 
False 
 Incorrect. Refer to Section 7 Lesson 3.  50. Static methods can write to instance variables. True or false? Mark for Review  (1) Points  True 
False (*) 
 Correct 
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 4  (Answer all questions in this section)

Tidak ada komentar:

Posting Komentar

Post Top Ad

Your Ad Spot

Pages