0

programming languages Online Quiz - 317

Description: programming languages Online Quiz - 317
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0
  1. The type List is assignable to List.

  2. The type List is assignable to List>.

  3. The type List is assignable to List extends B>.

  4. The type List extends A> is assignable to List.

  5. The type List is assignable to any List reference.

  6. The type List extends B> is assignable to List extends A>.


Correct Option: B,C,F

class Sub extends Super{ String name; Sub(String s) { super(s); name=s; } public static void main(String args[]){ Super sup = new Super("First"); Sub sub = new Sub("Second"); System.out.println(sub.name + " " + sup.name); } } class Super{ String name; Super(String s){ name =s ; } }

  1. Error: Super(java.lang.String) in Super cannot be applied to ()

  2. First Second

  3. Second First

  4. Runtime Exception


Correct Option: C

Given: 1. package com.company.application; 2. 3. public class MainClass { 4. public static void main(String[] args) { } 5. } And MainClass exists in the /apps/com/company/application directory. Assume the CLASSPATH environment variable is set to “.“ (current directory). Which two java commands entered at the command line will run MainClass? (Choose two.) A. java MainClass if run from the /apps directory B. java com.company.application.MainClass if run from the /apps directory C. java -classpath /apps com.company.application.MainClass if run from any directory D. java -classpath . MainClass if run from the /apps/com/company/application directory E. java -classpath /apps/com/company/application:. MainClass if run from the /apps directory F. java com.company.application.MainClass if run from the /apps/com/company/application directory

  1. A

  2. B

  3. C

  4. D

  5. E

  6. F


Correct Option: B,C

AI Explanation

To determine which java commands will run the MainClass, we need to consider the CLASSPATH environment variable and the location of the MainClass file. Let's go through each option to determine whether it is correct or incorrect:

Option A) java MainClass if run from the /apps directory - This option is incorrect because the MainClass file is not in the current directory. The command will not be able to find the MainClass file.

Option B) java com.company.application.MainClass if run from the /apps directory - This option is correct because it specifies the fully qualified name of the MainClass and the command is executed from the directory that contains the MainClass file.

Option C) java -classpath /apps com.company.application.MainClass if run from any directory - This option is correct because it specifies the classpath to be the /apps directory, which contains the MainClass file. The command can be executed from any directory.

Option D) java -classpath . MainClass if run from the /apps/com/company/application directory - This option is incorrect because it does not specify the fully qualified name of the MainClass. The command will not be able to find the MainClass file.

Option E) java -classpath /apps/com/company/application:. MainClass if run from the /apps directory - This option is incorrect because it does not specify the fully qualified name of the MainClass. The command will not be able to find the MainClass file.

Option F) java com.company.application.MainClass if run from the /apps/com/company/application directory - This option is incorrect because it does not include the classpath. The command will not be able to find the MainClass file.

The correct answers are B and C. These options specify the fully qualified name of the MainClass and include the correct classpath to locate the MainClass file.

Click the Exhibit button. 10. class Inner { 11. private int x; 12. public void setX( int x) { this.x = x; } 13. public int getX() { return x; } 14. } 15. 16. class Outer { 17. private Inner y; 18. public void setY( Inner y) { this.y = y; } 19. public Inner getY() { return y; } 20. } 21. 22. public class Gamma { 23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner(); 26.int n=10; 27. i.setX(n); 28. o.setY(i); 29. // insert code here 30. System.out.println( o.getY().getX()); 31. } 32. } Which three code fragments, added individually at line 29, produce the output 100? (Choose three.)

  1. n = 100;

  2. i.setX( 100);

  3. o.getY().setX( 100);

  4. i = new Inner(); i.setX( 100);

  5. o.setY( i); i = new Inner(); i.setX( 100);

  6. i = new Inner(); i.setX( 100); o.setY( i);


Correct Option: B,C,F

AI Explanation

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

Option A) n = 100; - This option is incorrect because it assigns the value of 100 to the variable n, but it does not modify the value of x in the Inner object i that is stored in the Outer object o.

Option B) i.setX(100); - This option is correct because it directly sets the value of x in the Inner object i to 100.

Option C) o.getY().setX(100); - This option is correct because it first retrieves the Inner object i stored in the Outer object o using the getY() method, and then sets the value of x in the Inner object to 100 using the setX() method.

Option D) i = new Inner(); i.setX(100); - This option is incorrect because it creates a new Inner object i and sets its value of x to 100, but it does not update the Inner object that is stored in the Outer object o.

Option E) o.setY(i); i = new Inner(); i.setX(100); - This option is incorrect because it first sets the Inner object i as the value of y in the Outer object o, but then it creates a new Inner object i and sets its value of x to 100. This new Inner object is not stored in the Outer object o.

Option F) i = new Inner(); i.setX(100); o.setY(i); - This option is correct because it first creates a new Inner object i and sets its value of x to 100. Then, it sets this Inner object as the value of y in the Outer object o.

The correct answers are B, C, and F. These options modify the value of x in the Inner object i that is stored in the Outer object o, resulting in the output of 100 when o.getY().getX() is called at line 30.

Given: 1. public class TestString3 { 2. public static void main(String[] args) { 3. // insert code here 5. System.out.println(s); 6. } 7. } Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.) A. String s = “123456789”; s = (s-”123”).replace(1,3,”24”) - “89”; B. StringBuffer s = new StringBuffer(”123456789”); s.delete(0,3).replace( 1,3, “24”).delete(4,6); C. StringBuffer s = new StringBuffer(”123456789”); s.substring(3,6).delete( 1 ,3).insert( 1, “24”); D. StringBuilder s = new StringBuilder(”123456789”); s.substring(3,6).delete( 1 ,2).insert( 1, “24”); E. StringBuilder s = new StringBuilder(”123456789”); s.delete(0,3).delete( 1 ,3).delete(2,5).insert( 1, “24”);

  1. A

  2. B

  3. C

  4. D

  5. E


Correct Option: B,E

AI Explanation

To determine which code fragments inserted independently at line 3 generate the output 4247, let's go through each option:

Option A) String s = "123456789"; s = (s-"123").replace(1,3,"24") - "89"; This code will not compile because you cannot subtract a string from another string. Additionally, the replace() method does not have a subtract operator. Therefore, this option is incorrect.

Option B) StringBuffer s = new StringBuffer("123456789"); s.delete(0,3).replace(1,3, "24").delete(4,6); This code fragment will generate the output 4247.

  • The delete(0,3) method deletes the characters from index 0 to index 3 in the string, resulting in "456789".
  • The replace(1,3, "24") method replaces the characters from index 1 to index 3 with "24", resulting in "424789".
  • The delete(4,6) method deletes the characters from index 4 to index 6 in the string, resulting in "4247".

Therefore, this option is correct.

Option C) StringBuffer s = new StringBuffer("123456789"); s.substring(3,6).delete(1 ,3).insert(1, "24"); This code will not generate the output 4247.

  • The substring(3,6) method returns the substring from index 3 to index 6, resulting in "456".
  • The delete(1,3) method deletes the characters from index 1 to index 3 in the substring, resulting in "46".
  • The insert(1, "24") method inserts the string "24" at index 1 in the substring, resulting in "4246".

Therefore, this option is incorrect.

Option D) StringBuilder s = new StringBuilder("123456789"); s.substring(3,6).delete(1,2).insert(1, "24"); This code will not generate the output 4247.

  • The substring(3,6) method returns the substring from index 3 to index 6, resulting in "456".
  • The delete(1,2) method deletes the character at index 1 in the substring, resulting in "46".
  • The insert(1, "24") method inserts the string "24" at index 1 in the substring, resulting in "4246".

Therefore, this option is incorrect.

Option E) StringBuilder s = new StringBuilder("123456789"); s.delete(0,3).delete(1,3).delete(2,5).insert(1, "24"); This code fragment will generate the output 4247.

  • The delete(0,3) method deletes the characters from index 0 to index 3 in the string, resulting in "456789".
  • The delete(1,3) method deletes the characters from index 1 to index 3 in the string, resulting in "479".
  • The delete(2,5) method deletes the characters from index 2 to index 5 in the string, resulting in "47".
  • The insert(1, "24") method inserts the string "24" at index 1 in the string, resulting in "4247".

Therefore, this option is correct.

The correct answers are B and E.

Click the Exhibit button. 1. public class A { 2. public void method1() { 3. B b=new B(); 4. b.method2(); 5. // more code here 6. } 7. } 1. public class B { 2. public void method2() { 3.C c=new C(); 4. c.method3(); 5. // more code here 6. } 7. } 1. public class C { 2. public void method3() { 3. // more code here 4. } 5. } Given: 25. try { 26. A a=new A(); 27. a.method1(); 28. } catch (Exception e) { 29. System.out.print(”an error occurred”); 30. } Which two are true if a NullPointerException is thrown on line 3 of class C? (Choose two.)

  1. The application will crash.

  2. The code on line 29 will be executed.

  3. The code on line 5 of class A will execute.

  4. The code on line 5 of class B will execute.

  5. The exception will be propagated back to line 27.


Correct Option: B,E

AI Explanation

To answer this question, let's analyze the code and go through each option to determine which ones are true if a NullPointerException is thrown on line 3 of class C.

Given code:

1. public class A {
2.     public void method1() {
3.         B b = new B();
4.         b.method2();
5.         // more code here
6.     }
7. }

1. public class B {
2.     public void method2() {
3.         C c = new C();
4.         c.method3();
5.         // more code here
6.     }
7. }

1. public class C {
2.     public void method3() {
3.         // more code here
4.     }
5. }

25. try {
26.     A a = new A();
27.     a.method1();
28. } catch (Exception e) {
29.     System.out.print("an error occurred");
30. }

Options:

A. The application will crash. B. The code on line 29 will be executed. C. The code on line 5 of class A will execute. D. The code on line 5 of class B will execute. E. The exception will be propagated back to line 27.

Let's analyze each option:

Option A) The application will crash - This option is incorrect because the application will not crash. When a NullPointerException is thrown, it can be caught by an exception handler to prevent the application from crashing.

Option B) The code on line 29 will be executed - This option is correct. Since a NullPointerException is thrown on line 3 of class C, the catch block starting on line 28 will catch the exception, and the code on line 29 (System.out.print("an error occurred");) will be executed.

Option C) The code on line 5 of class A will execute - This option is incorrect. If a NullPointerException is thrown on line 3 of class C, the execution of method1 in class A will not reach line 5 because the exception will be caught in the catch block on line 28.

Option D) The code on line 5 of class B will execute - This option is incorrect. If a NullPointerException is thrown on line 3 of class C, the execution of method2 in class B will not reach line 5 because the exception will be caught in the catch block on line 28.

Option E) The exception will be propagated back to line 27 - This option is correct. If a NullPointerException is thrown on line 3 of class C, the catch block on line 28 will catch the exception, and the control flow will propagate back to line 27 (a.method1();).

Therefore, the correct options are B and E.

Given: 33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(”a”); 37. } catch (RuntimeException e2) { 38. System.out.print(”b”); 39. } finally { 40. System.out.print(”c”); 41. } What is the result if a NullPointerException occurs on line 34?

  1. c

  2. a

  3. ab

  4. ac

  5. bc

  6. abc


Correct Option: D

AI Explanation

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

Option A) c - This option is incorrect because the "finally" block will always execute regardless of whether an exception is caught or not. Therefore, even if a NullPointerException occurs, "c" will be printed in addition to any other letters that may be printed.

Option B) a - This option is incorrect because if a NullPointerException occurs, the catch block for NullPointerException (line 36) will execute and print "a". However, the "finally" block will also execute and print "c". Therefore, the correct output will include both "a" and "c".

Option C) ab - This option is incorrect because if a NullPointerException occurs, the catch block for NullPointerException (line 36) will execute and print "a". However, the "finally" block will also execute and print "c". Therefore, the correct output will include both "a" and "c", but not "b".

Option D) ac - This option is correct because if a NullPointerException occurs, the catch block for NullPointerException (line 36) will execute and print "a". The "finally" block will also execute and print "c". Therefore, the correct output will include both "a" and "c".

Option E) bc - This option is incorrect because if a NullPointerException occurs, the catch block for NullPointerException (line 36) will execute and print "a". However, the "finally" block will also execute and print "c". Therefore, the correct output will include both "a" and "c", but not "b".

Option F) abc - This option is incorrect because if a NullPointerException occurs, the catch block for NullPointerException (line 36) will execute and print "a". The "finally" block will also execute and print "c". Therefore, the correct output will include both "a" and "c". However, the catch block for RuntimeException (line 38) will not execute because the exception is specifically caught by the catch block for NullPointerException.

The correct answer is Option D) ac. This option is correct because if a NullPointerException occurs, the catch block for NullPointerException (line 36) will execute and print "a". The "finally" block will also execute and print "c". Therefore, the correct output will include both "a" and "c".

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( RED.getRGB() < BLUE.getRGB() ) {}

  5. Color purple = Color.BLUE + Color.RED;

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


Correct Option: B,F

AI Explanation

To answer this question, let's review each of the given options:

Option A) Color skyColor = BLUE; This option assigns the enum constant "BLUE" to the variable "skyColor". This is incorrect because "BLUE" is a member of the "Color" enum and should be accessed as "Color.BLUE".

Option B) Color treeColor = Color.GREEN; This option correctly assigns the enum constant "GREEN" from the "Color" enum to the variable "treeColor". This is a valid way to access enum constants.

Option C) Color purple = new Color(0xff00ff); This option attempts to create a new enum constant using the constructor of the "Color" enum. However, enum constants are predefined and cannot be created using the constructor. This is incorrect.

Option D) if (RED.getRGB() < BLUE.getRGB()) {} This option correctly accesses the "getRGB()" method of the "RED" and "BLUE" enum constants and performs a comparison. This is a valid way to access enum constants and their methods.

Option E) Color purple = Color.BLUE + Color.RED; This option attempts to add the enum constants "BLUE" and "RED". However, enum constants cannot be added together using the "+" operator. This is incorrect.

Option F) if (Color.RED.ordinal() < Color.BLUE.ordinal()) {} This option correctly accesses the "ordinal()" method of the "RED" and "BLUE" enum constants and performs a comparison. This is a valid way to access enum constants and their methods.

Therefore, the correct options are B) Color treeColor = Color.GREEN; and F) if (Color.RED.ordinal() < Color.BLUE.ordinal()).

  1. Task View and Gnatt Chart View

  2. Task View, Time View and Workflow View

  3. Task View, Gnatt Chart View and workflow view

  4. Gnatt View and Workflow view


Correct Option: A
  1. Create user

  2. Create folders

  3. Assign privileges

  4. All of the above


Correct Option: D
  1. Informatica Server

  2. Repository Server

  3. Both A and B

  4. Neither A nor B


Correct Option: C
  1. Tasks must be within Workflows in order to be executed

  2. Workflows must be within Tasks to be executed

  3. Workflow links may contain conditions

  4. A start task is default task in a Workflow


Correct Option: B
  1. Relational Databases

  2. Relational Databases and flat files

  3. Relational Databases,lat files and cobol

  4. Relational Databases,lat files,cobol and certified ERP sources such as Peoplesoft and SAP R/3


Correct Option: D
  1. Run the Debugger, validate mappings and mapplets, import source definitions

  2. Run the debugger, create and delete folders, import source definitions

  3. Create and delete folders, view object dependencies, import source definitions

  4. Create and delete folders, create and edit mappings, create target tables


Correct Option: A

Choose the correct option - Transformations which have only Input/Output ports

  1. Expression

  2. Router

  3. Lookup

  4. Aggregator


Correct Option: A
- Hide questions