0

programming languages Online Quiz - 295

Description: programming languages Online Quiz - 295
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

What class need to be used to validate values entered in a form before saving?

  1. UIDOC

  2. DOC

  3. Notes

  4. Notesvalue


Correct Option: A

If you would like to restrict access to a particular document where will you store the persons name to give access

  1. Managers Field

  2. Editors Field

  3. Authors Field

  4. Readers Field


Correct Option: C

If I would need to attach document ina field what type of field has to be created?

  1. Text

  2. Attach Text

  3. Text Lite

  4. Rich Text


Correct Option: D
  1. public static void parse(String str) { 12. try { 13. float f= Float.parseFloat(str); 14. } catch (NumberFormatException nfe) { 15. f= 0; 16. } finally { 17. System.out.println(f); 18. } 19. } 20. public static void main(String[] args) { 21. parse(”invalid”); 22. } What is the result?
  1. 0.0

  2. Compilation fails

  3. A ParseException is thrown by the parse method at runtime

  4. A NumberFormatException is thrown by the parse method at runtime


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) 0.0 - This option is incorrect because the variable f is declared and initialized inside the try block and is not accessible outside the try block. Therefore, it cannot be printed in the finally block.

Option B) Compilation fails - This option is correct. The code will not compile because the variable f is declared inside the try block and is not accessible outside the try block. Therefore, when trying to print f in the finally block, a compilation error will occur.

Option C) A ParseException is thrown by the parse method at runtime - This option is incorrect because the code does not handle a ParseException. Instead, it catches a NumberFormatException in the catch block.

Option D) A NumberFormatException is thrown by the parse method at runtime - This option is incorrect because the code does not throw a NumberFormatException. Instead, it catches a NumberFormatException in the catch block.

The correct answer is B. Compilation fails because the variable f is declared inside the try block and is not accessible outside the try block.

Click the Exhibit button. 1. public class Test { 2. int x= 12; 3. public void method(int x) { 4. x+=x; 5. System.out.println(x); 6. } 7. } Given: 34. Test t = new Test(); 35. t.method(5); What is the output from line 5 of the Test class?

  1. 5

  2. 10

  3. 12

  4. 17


Correct Option: B

Given: 55. int []x= {1, 2,3,4, 5}; 56.int y[] =x; 57. System.out.println(y[2]); Which is true?

  1. Line 57 will print the value 2

  2. Line 57 will print the value 3

  3. Compilation will fail because of an error in line 55

  4. Compilation will fail because of an error in line 56


Correct Option: B

Given: 35. String #name = “Jane Doe”; 36.int$age=24; 37. Double_height = 123.5; 38. double~temp = 37.5; Which two are true? (Choose two.)

  1. Line 35 will not compile.

  2. Line 36 will not compile

  3. Line 37 will not compile.

  4. Line 38 will not compile.


Correct Option: A,D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Line 35 will not compile. In Java, when declaring a variable, the variable name must start with a letter, underscore, or a dollar sign. In this case, the variable name starts with a pound sign (#), which is not a valid character. Therefore, Line 35 will not compile.

Option B) Line 36 will not compile. In Java, the variable type should come before the variable name. In this case, the variable type is specified as "int$", which is not a valid type declaration. Therefore, Line 36 will not compile.

Option C) Line 37 will not compile. Line 37 declares a variable named "Double_height" of type Double. The variable name starts with an uppercase letter, which is allowed in Java, but it is considered a bad practice. However, the code will compile and run without any issues. Therefore, Line 37 will compile.

Option D) Line 38 will not compile. In Java, the variable name cannot contain special characters like "~". Therefore, Line 38 will not compile.

The correct answer is A and D. Line 35 will not compile because the variable name starts with a pound sign (#), and Line 38 will not compile because the variable name contains a special character (~).

Given: 11. public class Ball { 12. public enum Color { RED, GREEN, BLUE }; 13. public void foo() { 14. // insert code here 15. { System.out.println(c); } 16. } 17. } Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?

  1. for( Color c : Color.values())

  2. for( Color c = RED; c <= BLUE; c++)

  3. for( Color c; c.hasNext() ; c.next())

  4. for( Color c = Color[0]; c <= Color[2]; c++)


Correct Option: A
Explanation:

To solve this question, the user needs to know how to iterate through an enum in Java.

Option A is correct because it uses the values() method provided by the Color enum to iterate through all the possible values, and prints each one to the console.

Option B is incorrect because it treats the Color enum as if it were an integer, which it is not. It also uses an incorrect syntax for the for loop header.

Option C is incorrect because there is no hasNext() method for enums in Java. This is a method provided by the Iterator interface, which enums do not implement.

Option D is incorrect because there is no Color[0] syntax in Java. Additionally, the enum values are not guaranteed to be stored in an array in the order they are defined.

Therefore, the correct answer is:

The Answer is: A. for( Color c : Color.values())

Given: 11. public enum Title { 12. MR(”Mr.”), MRS(”Mrs.”), MS(”Ms.”); 13. private final String title; 14. private Title(String t) { title = t; } 15. public String format(String last, String first) { 16. return title + “ “ + first + “ “ + last; 17. } 18. } 19. public static void main(String[] args) { 20. System.out.println(Title.MR.format(”Doe”, “John”)); 21. } What is the result?

  1. Mr. John Doe

  2. An exception is thrown at runtime

  3. Compilation fails because of an error in line 12

  4. Compilation fails because of an error in line 15


Correct Option: A
  1. 1 2 3

  2. Compilation fails because of an error in line 12.

  3. Compilation fails because of an error in line 13

  4. Compilation fails because of an error in line 14


Correct Option: A
Explanation:

To solve this question, the user needs to know about arrays and casting in Java. The code initializes an Object obj to an array of integers with values 1, 2, and 3. It then casts the object to an array of integers and assigns it to the someArray variable. Finally, it uses a for-each loop to print out each element of the someArray array.

Now, let's go through each option and explain why it is right or wrong:

A. 1 2 3: This option is correct. The code initializes an array of integers with values 1, 2, and 3, casts it to an array of integers, and then prints out each element of the array using a for-each loop. This results in the output "1 2 3".

B. Compilation fails because of an error in line 12: This option is incorrect. Line 12 initializes an object to an array of integers, which is allowed in Java. There is no compilation error in this line.

C. Compilation fails because of an error in line 13: This option is incorrect. Line 13 casts the obj object to an array of integers, which is also allowed in Java. There is no compilation error in this line.

D. Compilation fails because of an error in line 14: This option is incorrect. Line 14 uses a for-each loop to print out each element of the someArray array, which is also allowed in Java. There is no compilation error in this line.

Therefore, the answer is:

The Answer is: A. 1 2 3

  1. Foo.beta() is a valid invocation of beta().

  2. Foo.alpha() is a valid invocation of alpha().

  3. Method beta() can directly call method alpha().

  4. Method alpha() can directly call method beta().


Correct Option: B,C
  1. itemID(int itemId)

  2. update(int itemId)

  3. setItemId(int itemId)

  4. mutateItemId(int itemId)


Correct Option: C
Explanation:

To solve this question, the user needs to understand the naming conventions used in JavaBeans to create setter methods for private instance variables.

According to JavaBeans conventions, setter methods for private instance variables should be named in the format setVariableName. Therefore, the correct method signature to modify the itemId instance variable in the Inventoryltem class should be:

C. setItemId(int itemId)

Option A: itemID(int itemId) is not following the JavaBeans naming standards for setter methods. The method name should start with the prefix set followed by the variable name.

Option B: update(int itemId) does not follow the JavaBeans naming conventions. The method name should start with the prefix set followed by the variable name.

Option D: mutateItemId(int itemId) is not a standard JavaBeans naming convention. The method name should start with the prefix set followed by the variable name.

Therefore, the correct answer is:

The Answer is: C. setItemId(int itemId)

Given: 10. class One { 11. public One foo() { return this; } 12. } 13. class Two extends One { 14. public One foo() { return this; } 15. } 16. class Three extends Two { 17. // insert method here 18. } Which two methods, inserted individually, correctly complete the Three class? (Choose two.)

  1. public void foo() { }

  2. public int foo() { return 3; }

  3. public Two foo() { return this; }

  4. public Object foo() { return this; }


Correct Option: C,D
  1. int foo() { /* more code here */ }

  2. void foo() { /* more code here */ }

  3. public void foo() { /* more code here */ }

  4. protected void foo() { /* more code here */ }


Correct Option: B,C,D
  1. Compilation will succeed for all classes and interfaces.

  2. Compilation of class C will fail because of an error in line 2.

  3. Compilation of class C will fail because of an error in line 6.

  4. Compilation of class AImpl will fail because of an error in line 2.


Correct Option: C
Explanation:

To solve this question, users need to understand the concept of interfaces and inheritance in Java programming language.

  • The interface A declares a method called doSomething that takes a string parameter.
  • The class AImpl implements the A interface and provides an implementation for the doSomething method.
  • The class B declares a method called doit that returns an object of type A.
  • The class C extends B and declares a method called doit that returns an object of type AImpl. It also declares a method called execute that overrides the execute method in class B and returns an object of type Object.

Now let's go through each option:

A. Compilation will succeed for all classes and interfaces.

This option is incorrect. Although there are no syntax errors in the code, there is a logical error in class C. It overrides the doit method in class B with a method that returns AImpl instead of A. This violates the Liskov Substitution Principle, which states that subclasses should be substitutable for their base classes. As a result, compilation will fail for class C.

B. Compilation of class C will fail because of an error in line 2.

This option is incorrect. There are no syntax errors in line 2 of class C. The error is a logical error, as explained above.

C. Compilation of class C will fail because of an error in line 6.

This option is correct. The execute method in class C attempts to override the execute method in class B. However, the return type of the method in class C is Object, which is not a subtype of the return type of the method in class B, which is String. As a result, compilation will fail for class C.

D. Compilation of class AImpl will fail because of an error in line 2.

This option is incorrect. There are no syntax errors in line 2 of class AImpl.

Therefore, the correct answer is:

The Answer is: C. Compilation of class C will fail because of an error in line 6.

Click the Exhibit button. 1. public class A { 2. public String doit(int x, int y) { 3. return “a”; 4. } 5. 6. public String doit(int... vals) { 7. return “b”; 8. } 9. } Given: 25. A a=new A(); 26. System.out.println(a.doit(4, 5)); What is the result?

  1. Line 26 prints “a” to System.out

  2. Line 26 prints ‘b” to System.out

  3. An exception is thrown at line 26 at runtime.

  4. Compilation of class A will fail due to an error in line 6


Correct Option: A
Explanation:

To solve this question, the user should understand the concept of method overloading and how Java resolves the method call based on the number and type of arguments passed.

In the given code, class A has two methods named doit. One method takes two integer arguments, and the other takes an arbitrary number of integer arguments.

When we call a.doit(4,5) on line 26, Java examines both methods in class A that are named doit and checks to see which one matches the argument types. Since there is a doit method with two integer parameters, Java selects that method, and the String "a" is returned by that method.

Therefore, the output of the given code is:

The Answer is: A. Line 26 prints “a” to System.out.

- Hide questions