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 formula should be used to get a date, 2 months from todays date?

  1. @Text

  2. @Adjust

  3. @Date

  4. @Month


Correct Option: B

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

Given: 10. public class Fabric 11. public enum Color { 12. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff); 13. private final int rgb; 14. Color( int rgb) { this.rgb = rgb; } 15. public int getRGB() { return rgb; } 16. }; 17. public static void main( String[] argv) { 18. // insert code here 19. } 20. } Which two code fragments, inserted independently at line 18, allow the Fabric class to compile? (Choose two.)

  1. Color skyColor = BLUE;

  2. Color treeColor = Color.GREEN;

  3. Color purple = new Color( 0xff00ff);

  4. if( Color.RED.ordinal() < Color.BLUE.ordinal() ) {}


Correct Option: B,D

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

Given: 11. public static void main(String[] args) { 12. Object obj =new int[] { 1,2,3 }; 13. int[] someArray = (int[])obj; 14. for (int i: someArray) System.out.print(i +“ “) 15. } ‘What is the result?

  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

Given: 10. class Foo { 11. static void alpha() { /* more code here / } 12. void beta() { / more code here */ } 13. } Which two are true? (Choose two.)

  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

AI Explanation

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

Option A) Foo.beta() is a valid invocation of beta() - This option is incorrect because the beta() method is an instance method and cannot be invoked using the class name. It should be invoked on an instance of the Foo class.

Option B) Foo.alpha() is a valid invocation of alpha() - This option is correct. The alpha() method is a static method, and static methods can be invoked using the class name.

Option C) Method beta() can directly call method alpha() - This option is correct. Since both beta() and alpha() are methods of the same class, the beta() method can directly call the alpha() method without any issues.

Option D) Method alpha() can directly call method beta() - This option is incorrect. The alpha() method is a static method, while the beta() method is an instance method. Static methods cannot directly call instance methods without creating an instance of the class.

The correct answers are B and C.

A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways: logIt(”log message 1 “); logIt(”log message2”,”log message3”); logIt(”log message4”, “log message5”, “log message6); Which declaration satisfies this requirement?

  1. public void logIt(String * msgs)

  2. public void logIt(String [] msgs)

  3. public void logIt(String... msgs)

  4. public void logIt(String msg1, String msg2, String msg3)


Correct Option: C

A programmer is designing a class to encapsulate the information about an inventory item. A JavaBeans component is needed to do this. The Inventoryltem class has private instance variables to store the item information: 10. private int itemId; 11. private String name; 12. private String description; Which method signature follows the JavaBeans naming standards for modifying the itemld instance variable?

  1. itemID(int itemId)

  2. update(int itemId)

  3. setItemId(int itemId)

  4. mutateItemId(int itemId)


Correct Option: C

Click the Exhibit button. 1. public class A { 2. 3. private int counter = 0; 4. 5. public static int getInstanceCount() { 6. return counter; 7. } 8. 9. public A() { 10. counter++; 11. } 12. 13. } Given this code from Class B: 25.A a1 =new A(); 26. A a2 =new A(); 27. A a3 =new A(); 28. System.out.printIn(A.getInstanceCount() ); What is the result?

  1. Compilation of class A fails

  2. Line 28 prints the value 3 to System.out

  3. Line 28 prints the value 1 to System.out.

  4. A runtime error occurs when line 25 executes


Correct Option: A

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

Given: 10. class One { 11. void foo() {} 12. } 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)

  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

AI Explanation

To answer this question, we need to understand the concept of method overriding and access modifiers in Java.

In Java, when a class extends another class, it inherits all the methods from the superclass. However, if the subclass needs to provide a different implementation of a method inherited from the superclass, it can override the method.

In this scenario, class Two extends class One, which means that it inherits the method foo() from class One. To correctly complete class Two, we need to override the foo() method with the correct access modifier.

Let's go through each option to understand why it is correct or incorrect:

Option A) int foo() { /* more code here */ } This option is incorrect because it changes the return type of the foo() method, which is not allowed when overriding a method.

Option B) void foo() { /* more code here */ } This option is correct because it overrides the foo() method with the same return type and access modifier.

Option C) public void foo() { /* more code here */ } This option is correct because it overrides the foo() method with the same return type and a broader access modifier (public is broader than the default access modifier).

Option D) protected void foo() { /* more code here */ } This option is correct because it overrides the foo() method with the same return type and a broader access modifier (protected is broader than the default access modifier).

The correct answers are B), C), and D). These options correctly complete class Two by overriding the foo() method with the same return type and appropriate access modifiers.

Click the Exhibit button. 1. public interface A { 2. public void doSomething(String thing); 3. } 1. public class AImpl implements A { 2. public void doSomething(String msg) { } 3. } 1. public class B { 2. public A doit() { 3. // more code here 4. } 5. 6. public String execute() { 7. // more code here 8. } 9. } 1. public class C extends B { 2. public AImpl doit() { 3. // more code here 4. } 5. 6. public Object execute() { 7. // more code here 8. } 9. } Which statement is true about the classes and interfaces in the exhibit?

  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

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
- Hide questions