0

web technology Online Quiz - 115

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

Which of the following are primitive types?

  1. byte

  2. String

  3. integer

  4. Float


Correct Option: A

Choose the technologies used in view part of MVC architecture

  1. HTML

  2. CSS

  3. EJB

  4. Servlets


Correct Option: A,B

Controller in PS Framework is

  1. ps.xml

  2. Action controller

  3. JSP file

  4. Servlet


Correct Option: A,B

Which one does not extend java.lang.Number

  1. Integer

  2. Boolean

  3. Character

  4. Long


Correct Option: A,B
Explanation:

To solve this question, the user needs to know the concepts of inheritance and the java.lang.Number class. The java.lang.Number class is the superclass of all classes that encapsulate numbers in Java. These classes include Integer, Double, Long, Byte, Float, and Short.

Now, let's go through each option and explain why it extends or does not extend java.lang.Number:

A. Integer: This option extends java.lang.Number. Integer is a class that represents a 32-bit signed integer. It is a subclass of java.lang.Number and inherits its methods.

B. Boolean: This option does not extend java.lang.Number. Boolean is a class that represents a boolean value, which is either true or false. It does not inherit from java.lang.Number.

C. Character: This option does not extend java.lang.Number. Character is a class that represents a single character. It does not inherit from java.lang.Number.

D. Long: This option extends java.lang.Number. Long is a class that represents a 64-bit signed integer. It is a subclass of java.lang.Number and inherits its methods.

Therefore, the answer is:

The Answer is: B

Given: class Top { public Top(String s) { System.out.print("B"); } } public class Bottom2 extends Top { public Bottom2(String s) { System.out.print("D"); } public static void main(String [] args) { new Bottom2("C"); System.out.println(" "); } } What is the result?

  1. BD

  2. DB

  3. BDC

  4. DBC

  5. Compilation fails


Correct Option: E

Which statement(s) are true? (Choose all that apply.)

  1. Cohesion is the OO principle most closely associated with hiding implementation details

  2. Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs

  3. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose

  4. Cohesion is the OO principle most closely associated with allowing a single object to be seen as having many types


Correct Option: C

AI Explanation

To answer this question, we need to understand the concept of cohesion in object-oriented programming (OOP).

Cohesion is the measure of how closely the responsibilities and functionality of a class or module are related. It is an important principle in OOP design, as it promotes modularity, maintainability, and reusability.

Let's go through each statement to determine which one(s) are true:

A. Cohesion is the OO principle most closely associated with hiding implementation details. This statement is incorrect. Hiding implementation details is more closely associated with the principle of encapsulation, not cohesion.

B. Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs. This statement is incorrect. Making sure that classes know about other classes only through their APIs is more closely associated with the principle of information hiding, not cohesion.

C. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose. This statement is true. Cohesion is all about ensuring that a class has a single, well-focused purpose. It means that the responsibilities and functionality of a class should be closely related and focused on achieving a specific goal.

D. Cohesion is the OO principle most closely associated with allowing a single object to be seen as having many types. This statement is incorrect. Allowing a single object to be seen as having many types is more closely associated with the principle of polymorphism, not cohesion.

Based on the explanations above, the correct statement is:

C. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose.

Therefore, the correct answer is C.

Given: 3. class Mammal { 4. String name = "furry "; 5. String makeNoise() { return "generic noise"; } 6. } 7. class Zebra extends Mammal { 8. String name = "stripes "; 9. String makeNoise() { return "bray"; } 10. } 11. public class ZooKeeper { 12. public static void main(String[] args) { new ZooKeeper().go(); } 13. void go() { 14. Mammal m = new Zebra(); 15. System.out.println(m.name + m.makeNoise()); 16. } 17. } What is the result?

  1. furry bray

  2. stripes bray

  3. furry generic noise

  4. stripes generic noise

  5. Compilation fails

  6. An exception is thrown at runtime


Correct Option: A

AI Explanation

To determine the result of the given code, let's go through each option:

Option A) furry bray - This option concatenates the name variable from the Mammal class, which is "furry", with the result of the makeNoise() method from the Zebra class, which is "bray".

Option B) stripes bray - This option concatenates the name variable from the Zebra class, which is "stripes", with the result of the makeNoise() method from the Zebra class, which is "bray". However, the name variable in the Mammal class is not used.

Option C) furry generic noise - This option concatenates the name variable from the Mammal class, which is "furry", with the result of the makeNoise() method from the Mammal class, which is "generic noise".

Option D) stripes generic noise - This option concatenates the name variable from the Zebra class, which is "stripes", with the result of the makeNoise() method from the Mammal class, which is "generic noise".

Option E) Compilation fails - There are no compilation errors in the given code, so this option is incorrect.

Option F) An exception is thrown at runtime - There are no exceptions thrown in the given code, so this option is incorrect.

The correct answer is Option A) furry bray. This option is correct because it correctly combines the name variable from the Mammal class with the result of the makeNoise() method from the Zebra class.

Given: ClassA has a ClassD Methods in ClassA use public methods in ClassB Methods in ClassC use public methods in ClassA Methods in ClassA use public variables in ClassB Which is most likely true? (Choose the most likely.)

  1. ClassD has low cohesion

  2. ClassA has weak encapsulation

  3. ClassB has weak encapsulation

  4. ClassB has strong encapsulation

  5. ClassC is tightly coupled to ClassA


Correct Option: C

Given: 3. import java.io.*; 4. public class ReadingFor { 5. public static void main(String[] args) { 6. String s; 7. try { 8. FileReader fr = new FileReader("myfile.txt"); 9. BufferedReader br = new BufferedReader(fr); 10. while((s = br.readLine()) != null) 11. System.out.println(s); 12. br.flush(); 13. } catch (IOException e) { System.out.println("io error"); } 16. } 17. } And given that myfile.txt contains the following two lines of data: ab cd What is the result?

  1. ab

  2. abcd

  3. ab cd

  4. a b c D

  5. Compilation fails


Correct Option: E

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

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

AI Explanation

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

Option A) -124 - This option is incorrect because the result will not include the number 1.

Option B) -134 - This option is incorrect because the result will not include the number 1.

Option C) -424 - This option is incorrect because the result will not include the number 2.

Option D) -434 - This option is correct because the result will include the numbers 4 and 3.

Option E) -444 - This option is incorrect because the result will not include the number 2.

Option F) Compilation fails - This option is incorrect because the code compiles successfully.

The correct answer is D. This option is correct because the result will include the numbers 4 and 3.

Explanation:

  • The main method calls the method sifter with different types of arguments: an array of type A[], an array of type B[], and an integer (7).
  • There are multiple overloaded versions of the sifter method: one that takes an array of type A[], one that takes an array of type B[], one that takes an array of type B[] with a variable number of parameters, and one that takes an Object.
  • When sifter(aa) is called, it matches the sifter method that takes an array of type A[], so s += "1" is executed.
  • When sifter(ba) is called, it matches the sifter method that takes an array of type B[], so s += "2" is executed.
  • When sifter(7) is called, it does not match any of the sifter methods directly, but it matches the sifter method that takes an Object, so s += "4" is executed.
  • Therefore, the value of s becomes "-434".
  • Finally, the value of s is printed, which is "-434".

Thus, the correct answer is D.

  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
Explanation:

To solve this question, the user needs to understand how the nested for loops work and the use of break statements inside loops.

The code starts with a nested for loop. The outer loop iterates over values of j from 0 to 4, while the inner loop iterates over values of k from 0 to 2. Inside the inner loop, the code prints the value of j and checks two conditions using if statements:

  • If j is equal to 3 and k is equal to 1, the code executes a break statement with the label "foreach", which causes the program to exit both loops and continue executing after line 13.
  • If j is equal to 0 or 2, the code executes a break statement, which only exits the inner loop and continues executing from line 12.

Now, let's go through each option and find the correct answer:

A. 0 1 2 3:

This option is incorrect. The inner loop will only execute when j is equal to 1 or 3, and k is less than 3. When j is equal to 3 and k is equal to 1, the program exits both loops and does not print any more values. Thus, the correct output should not include 4.

B. 1 1 1 3 3:

This option is incorrect. The inner loop will only execute when j is equal to 1 or 3, and k is less than 3. When j is equal to 3 and k is equal to 1, the program exits both loops and does not print any more values. Thus, the correct output should not include 1 or 2.

C. 0 1 1 1 2 3 3:

This option is correct. The inner loop will only execute when j is equal to 1 or 3, and k is less than 3. When j is equal to 3 and k is equal to 1, the program exits both loops and does not print any more values. Thus, the correct output is 0 1 1 1 2 3 3.

D. 1 1 1 3 3 4 4 4:

This option is incorrect. The program never prints the value 4, since the outer loop only iterates from 0 to 4. When j is equal to 3 and k is equal to 1, the program exits both loops and does not print any more values. Thus, the correct output should not include 1 or 2.

E. 0 1 1 1 2 3 3 4 4 4:

This option is incorrect. The program never prints the value 4, since the outer loop only iterates from 0 to 4. When j is equal to 3 and k is equal to 1, the program exits both loops and does not print any more values. Thus, the correct output should not include 1, 2, or 4.

F. Compilation fails:

This option is incorrect. The code compiles without errors.

Therefore, the correct answer is:

The answer is: C. 0 1 1 1 2 3 3.

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

AI Explanation

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

Option A) TUE - This option is incorrect. The output of the program is not TUE.

Option B) Wed - This option is correct. The output of the program is indeed "Wed" because the array d2 is assigned the values of the Days enum using the values() method. The values() method returns an array containing the enum constants in the order they were declared. In this case, the constants are declared as MON, TUE, WED, so d2[2] corresponds to WED.

Option C) The output is unpredictable - This option is incorrect. The output of the program is predictable and will always be "Wed".

Option D) Compilation fails due to an error on line 4 - This option is incorrect. There is no error on line 4. The enum Days is correctly declared and used.

Option E) Compilation fails due to an error on line 6 - This option is incorrect. There is no error on line 6. The for-each loop iterates over the enum constants correctly.

Option F) Compilation fails due to an error on line 8 - This option is incorrect. There is no error on line 8. The Days enum values are correctly assigned to the d2 array.

The correct answer is B) Wed. This option is correct because the program outputs "Wed" due to the assignment of Days enum values to the d2 array.

What is the output of the following StringBuffer sb1 = new StringBuffer("Amit"); StringBuffer sb2= new StringBuffer("Amit"); String ss1 = "Amit"; System.out.println(sb1==sb2); System.out.println(sb1.equals(sb2)); System.out.println(sb1.equals(ss1)); System.out.println("Poddar".substring(3));

  1. false false false dar

  2. false true false Poddar

  3. Compiler Error

  4. true true false dar


Correct Option: A

AI Explanation

To answer this question, let's go through each line of code and analyze the output:

StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2 = new StringBuffer("Amit");
String ss1 = "Amit";
System.out.println(sb1 == sb2);
System.out.println(sb1.equals(sb2));
System.out.println(sb1.equals(ss1));
System.out.println("Poddar".substring(3));
  1. StringBuffer sb1 = new StringBuffer("Amit"); creates a StringBuffer object sb1 with the value "Amit".
  2. StringBuffer sb2 = new StringBuffer("Amit"); creates another StringBuffer object sb2 with the value "Amit".
  3. String ss1 = "Amit"; creates a String object ss1 with the value "Amit".
  4. System.out.println(sb1 == sb2); compares the references of sb1 and sb2. Since they are two different objects, the comparison returns false.
  5. System.out.println(sb1.equals(sb2)); compares the contents of sb1 and sb2. Although they have the same value ("Amit"), the StringBuffer class does not override the equals method, so the comparison returns false.
  6. System.out.println(sb1.equals(ss1)); compares the contents of sb1 and ss1. They have different types (StringBuffer and String), so the comparison returns false.
  7. System.out.println("Poddar".substring(3)); extracts a substring from the string "Poddar" starting from index 3. The output is "dar".

Therefore, the correct answer is option A. The output will be:

false
false
false
dar

Which of the following are primitive types?

  1. byte

  2. String

  3. integer

  4. Float


Correct Option: A

What is the output (Assuming written inside main) String s1 = new String("amit"); String s2 = s1.replace('m','i'); s1.concat("Poddar"); System.out.println(s1); System.out.println((s1+s2).charAt(5));

  1. Compile error

  2. amitPoddar O

  3. amitPoddar I

  4. amit I


Correct Option: D

AI Explanation

To answer this question, let's go through each line of code:

  1. String s1 = new String("amit"); - This line creates a new String object s1 with the value "amit".

  2. String s2 = s1.replace('m','i'); - This line creates a new String object s2 by replacing the character 'm' with 'i' in s1. So, the value of s2 will be "aiit".

  3. s1.concat("Poddar"); - This line concatenates the string "Poddar" to s1, but the result is not assigned to any variable. Therefore, the value of s1 remains unchanged, which is still "amit".

  4. System.out.println(s1); - This line prints the value of s1, which is "amit".

  5. System.out.println((s1+s2).charAt(5)); - This line concatenates s1 and s2 using the + operator, resulting in "amitaiit". It then retrieves the character at index 5, which is 'a', and prints it.

The correct answer is D) "amit I".

What is the output of following (Assuming written inside main) String s1 = "Amit"; String s2 = "Amit"; String s3 = new String("abcd"); String s4 = new String("abcd"); System.out.println(s1.equals(s2)); System.out.println((s1==s2)); System.out.println(s3.equals(s4)); System.out.println((s3==s4));

  1. True true true false

  2. True true true true

  3. True false true false

  4. False false true false


Correct Option: A

AI Explanation

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

Option A) True true true false - This option is correct because it matches the output of the given code.

Option B) True true true true - This option is incorrect because the last statement (s3==s4) should evaluate to false. Although the content of the two strings is the same, they are created using the new keyword, which creates two different objects in memory. Therefore, the equality check using == returns false.

Option C) True false true false - This option is incorrect because the second statement (s1==s2) should evaluate to true. Since both s1 and s2 are initialized with the same string literal "Amit", they point to the same object in memory.

Option D) False false true false - This option is incorrect because the first statement (s1.equals(s2)) should evaluate to true. The equals() method compares the content of the strings, and since s1 and s2 contain the same value "Amit", the comparison returns true.

The correct answer is option A.

Which one does not extend java.lang.Number

  1. Integer

  2. Boolean

  3. Character

  4. Long


Correct Option: B,C

If the method to be overridden has access type protected, choose access types among the following that a subclass can have,

  1. Protected

  2. Private

  3. Public

  4. Public & private

  5. Protected & Public


Correct Option: E

While serializing a class whose Base class is serializable, which of the following fields are ignored?

  1. Non Static field

  2. Base class fields

  3. Transient Fields

  4. none


Correct Option: C
- Hide questions