0

web technology Online Quiz - 120

Description: web technology Online Quiz - 120
Number of Questions: 20
Created by:
Tags: web technology
Attempted 0/20 Correct 0 Score 0

XML is Case-Sensitive Language

  1. True

  2. False


Correct Option: B

Given: public static void before() { Set set = new TreeSet(); set.add("2"); set.add(3); set.add("1"); Iterator it = set.iterator(); while (it.hasNext()) System.out.print(it.next() + " "); } Which statements are true?

  1. The before() method will print 1 2

  2. The before() method will print 1 2 3

  3. The before() method will print three numbers, but the order cannot be determined

  4. The before() method will not compile

  5. The before() method will throw an exception at runtime


Correct Option: E

AI Explanation

To determine the output of the given code, let's analyze the code step by step:

  1. The code defines a method called before() with no parameters and a void return type.

  2. Inside the before() method, a TreeSet object named set is created.

  3. Three elements are added to the set:

    • The string "2"
    • The integer 3
    • The string "1"
  4. An iterator named it is created using the iterator() method of the set object.

  5. The code enters a while loop that continues as long as the iterator has a next element.

  6. Inside the loop, the next() method is called on the iterator and the result is printed using System.out.print().

Now, let's analyze each option:

Option A) The before() method will print 1 2

  • This option is incorrect. The TreeSet class sorts its elements in ascending order, and the elements "1" and "2" are added before the element 3. Therefore, the output will not be "1 2".

Option B) The before() method will print 1 2 3

  • This option is incorrect. As mentioned earlier, the TreeSet class sorts its elements in ascending order. The element 3 is added after the elements "1" and "2", so the output will not be "1 2 3".

Option C) The before() method will print three numbers, but the order cannot be determined

  • This option is incorrect. The TreeSet class guarantees that the elements will be sorted in ascending order. Therefore, the order can be determined, and it will not be random.

Option D) The before() method will not compile

  • This option is incorrect. The code does not contain any compilation errors, so the method will compile successfully.

Option E) The before() method will throw an exception at runtime

  • This option is correct. The TreeSet class does not allow elements of different types to be added. In this case, both strings and integers are added to the set. When the next() method is called on the iterator, it will throw a ClassCastException at runtime because it tries to cast an integer to a string. Therefore, the method will throw an exception at runtime.

The correct answer is option E.

Given: interface Hungry { void munch(E x); } interface Carnivore extends Hungry {} interface Herbivore extends Hungry {} abstract class Plant {} class Grass extends Plant {} abstract class Animal {} class Sheep extends Animal implements Herbivore { public void munch(Sheep x) {} } class Wolf extends Animal implements Carnivore { public void munch(Sheep x) {} } Which of the following changes (taken separately) would allow this code to compile? (Choose all that apply.)

  1. Change the Carnivore interface to interface Carnivore extends Hungry {}

  2. Change the Herbivore interface to interface Herbivore extends Hungry {}

  3. Change the Sheep class to class Sheep extends Animal implements Herbivore { public void munch(Grass x) {} }

  4. Change the Sheep class to class Sheep extends Plant implements Carnivore { public void munch(Wolf x) {} }

  5. Change the Wolf class to class Wolf extends Animal implements Herbivore { public void munch(Grass x) {} }

  6. No changes are necessary


Correct Option: B

Given: public static void main(String[] args) { // INSERT DECLARATION HERE for (int i = 0; i <= 10; i++) { List row = new ArrayList(); for (int j = 0; j <= 10; j++) row.add(i * j); table.add(row); } for (List row : table) System.out.println(row); } Which statements could be inserted at // INSERT DECLARATION HERE to allow this code to compile and run? (Choose all that apply.)

  1. List> table = new List>();

  2. List> table = new ArrayList>();

  3. List> table = new ArrayList>();

  4. List table = new List();

  5. List table = new ArrayList();

  6. List table = new ArrayList();


Correct Option: B

Given: 3. import java.util.*; 4. class Business { } 5. class Hotel extends Business { } 6. class Inn extends Hotel { } 7. public class Travel { 8. ArrayList go() { 9. // insert code here 10. } 11. } Which, inserted independently at line 9, will compile? (Choose all that apply.)

  1. return new ArrayList();

  2. return new ArrayList();

  3. return new ArrayList();

  4. return new ArrayList();


Correct Option: B

Which is true? (Choose all that apply.)

  1. "X extends Y" is correct if and only if X is a class and Y is an interface

  2. "X extends Y" is correct if and only if X is an interface and Y is a class

  3. "X extends Y" is correct if X and Y are either both classes or both interfaces

  4. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces


Correct Option: C

AI Explanation

To answer this question, we need to understand the concept of inheritance in object-oriented programming.

In object-oriented programming, the keyword "extends" is used to establish an inheritance relationship between classes and interfaces. Here are the explanations for each option:

Option A) "X extends Y" is correct if and only if X is a class and Y is an interface. This option is incorrect. In Java, a class can extend another class or implement an interface. The keyword "extends" is used for class inheritance, while the keyword "implements" is used for interface implementation.

Option B) "X extends Y" is correct if and only if X is an interface and Y is a class. This option is incorrect. In Java, an interface cannot extend a class. It can only extend another interface using the keyword "extends".

Option C) "X extends Y" is correct if X and Y are either both classes or both interfaces. This option is correct. In Java, a class can extend another class, and an interface can extend another interface. Therefore, "X extends Y" is correct if X and Y are either both classes or both interfaces.

Option D) "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces. This option is incorrect. As explained above, "X extends Y" is not correct for all combinations. It is only correct if X and Y are either both classes or both interfaces.

Therefore, the correct answer is option C.

Given: 3. class A { } 4. class B extends A { } 5. public class ComingThru { 6. static String s = "-"; 7. public static void main(String[] args) { 8. A[] aa = new A[2]; 9. B[] ba = new B[2]; 10. sifter(aa); 11. sifter(ba); 12. sifter(7); 13. System.out.println(s); 14. } 15. static void sifter(A[]... a2) { s += "1"; } 16. static void sifter(B[]... b1) { s += "2"; } 17. static void sifter(B[] b1) { s += "3"; } 18. static void sifter(Object o) { s += "4"; } 19. } What is the result?

  1. -124

  2. -134

  3. -424

  4. -434

  5. -444

  6. Compilation fails


Correct Option: D

Given: 3. public class Wind { 4. public static void main(String[] args) { 5. foreach: 6. for(int j=0; j<5; j++) { 7. for(int k=0; k< 3; k++) { 8. System.out.print(" " + j); 9. if(j==3 && k==1) break foreach; 10. if(j==0 || j==2) break; 11. } 12. } 13. } 14. } What is the result?

  1. 0 1 2 3

  2. 1 1 1 3 3

  3. 0 1 1 1 2 3 3

  4. 1 1 1 3 3 4 4 4

  5. 0 1 1 1 2 3 3 4 4 4

  6. Compilation fails


Correct Option: C

Given: 3. public class TestDays { 4. public enum Days { MON, TUE, WED }; 5. public static void main(String[] args) { 6. for(Days d : Days.values() ) 7. ; 8. Days [] d2 = Days.values(); 9. System.out.println(d2[2]); 10. } 11. } What is the result? (Choose all that apply.)

  1. TUE

  2. Wed

  3. The output is unpredictable

  4. Compilation fails due to an error on line 4

  5. Compilation fails due to an error on line 6

  6. Compilation fails due to an error on line 8


Correct Option: B

Given the proper import statement(s), and 13. PriorityQueue pq = new PriorityQueue(); 14. pq.add("2"); 15. pq.add("4"); 16. System.out.print(pq.peek() + " "); 17. pq.offer("1"); 18. pq.add("3"); 19. pq.remove("1"); 20. System.out.print(pq.poll() + " "); 21. if(pq.remove("2")) System.out.print(pq.poll() + " "); 22. System.out.println(pq.poll() + " " + pq.peek()); What is the result?

  1. 2 2 3 3

  2. 2 2 3 4

  3. 4 3 3 4

  4. 2 2 3 3 3

  5. 4 3 3 3 3

  6. 2 2 3 3 4


Correct Option: B

What is output to the web page on the second access to the same instance of the following JSP? (Choose one.) Chapter 6 Question 2

Chapter 6 Question 2

  1. 0

  2. 1

  3. 2

  4. 3

  5. 4

  6. Page does not translate.


Correct Option: D

In the UML notation a class can be represented by

  1. A rectangular box with the name of the class in the box

  2. A rectangular box with the name of the object, a : and the class name that the object belongs to

  3. A rectangular box with the class name prefixed by the word "class"

  4. A thin vertical line with key method calls shown as outward arrows

  5. A rectangular box with an inserted dashed box on the top right corner.


Correct Option: A

In the UML notation, an object can be represented by

  1. A comment or explanatory note associated with a class

  2. A rectangular box with the object name and the constraint "{object}" immediatly following it

  3. A rectangular box with the name of the object in the box.

  4. A rectangular box with the name of the object, a : and the class name that the object belongs to.

  5. A thin vertical line with key method calls shown as outward arrows .


Correct Option: D

Inheritance relationships are represented in the UML notation by:

  1. nesting of classes

  2. lines with a solid diamond at one end

  3. lines with a hollow diamond at one end

  4. lines with a triangular arrow at one end

  5. lines with a triangular arrow at both ends


Correct Option: D
  1. getSessionBehaviour()

  2. getApplicationId()

  3. getSecurityLevel()

  4. getServletName()


Correct Option: B

Which one is correct?

  1. Write name here

  2. Write name here

  3. Write name here

  4. Write name here


Correct Option: A
  1. Web.xml

  2. application.xml

  3. ps.xml

  4. Actionconfig.xml


Correct Option: B
  1. a time-line illustrating a typical sequence of calls between object function members

  2. a call tree illustrating all possible sequences of calls between class function members

  3. a time-line illustrating the changes in inheritance and instantiation relationships between classes and objects over time

  4. a tree illustrating inheritance and relationships between classes

  5. a directed acyclic graph illustrating inheritance and instantiation relationships between classes and objects


Correct Option: A
- Hide questions