Java Constructors and General Programming Quiz

A mixed quiz covering Java constructors, ASP.NET, .NET framework, C++ functions, AJAX, and various Java programming concepts including string manipulation and file operations.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What is the result of compiling and running the following code? String s=new String("hello"); StringBuffer sb=new StringBuffer("hello"); System.out.println(s.equals(sb));

  1. Compiler error: String and StringBuffer objects cannot be compared
  2. ClassCastException: String and StringBuffer objects cannot be compared
  3. Prints "true"
  4. Prints "false"
Question 2 Multiple Choice (Multiple Answers)

Which of the following compiles correctly if "f" is an instance of the File class?

  1. String[] s =f.list();
  2. File[] files=f.list();
  3. File[] files=f.listFiles();
  4. List files=f.listFiles();
Question 3 Multiple Choice (Single Answer)

What will happen when you attempt to compile and run the given code? 1. public class EqualsTest 2.{ 3. public static void main(String[] args) 4.{ 5. Boolean b = new Boolean(true); 6. String str = new String(""+b); 7. StringBuffer buff = new StringBuffer(str); 8. 9. System.out.println(b.equals(str) + ", " + 10. str.equals(buff) + ", " + 11. buff.equals(b)); 12. } 13. }

  1. It will print - false, true, false
  2. It will print - true, true, false
  3. It will print - false, false, false
  4. It will print - true, false, false
  5. Compilation error
  6. ClassCastException at runtime
Question 4 Multiple Choice (Multiple Answers)

Which of the following are true about the readPassword() method of the Console class? choose two

  1. Its return type is String
  2. It reads the password from the console
  3. It has echoing disabled
  4. It takes a single argument
  5. None of them
Question 5 Multiple Choice (Single Answer)

What is the result of compiling and running the following program? import java.util.Arrays; class Split2 { public static void main(String[] args) { String str = "She sells sea shells"; System.out.println(Arrays.toString(str.split("\s"))); } }

  1. Compiler error
  2. An exception is thrown at runtime
  3. Prints [She, sells, sea, shells]
  4. Prints [he, ells, ea, hells]
  5. Prints []
Question 6 Multiple Choice (Single Answer)

The .NET framework which provides automatic memory management using a technique called

  1. Overriding
  2. Garbage Collection
  3. Assemblies
  4. Serialization
Question 7 Multiple Choice (Single Answer)

Which browsers are supported by AJAX ?

  1. Internet Explorer 5.0
  2. Netscape 7.1
  3. Firefox 1.0
  4. All of Above
Question 8 Multiple Choice (Single Answer)

How to convert a string to integer?

  1. strtod()
  2. srttoi()
  3. atoi()
  4. None of these
Question 9 Multiple Choice (Single Answer)

What’s the .NET collection class that allows an element to be accessed using a unique key?

  1. ArrayList
  2. NameValue Collection
  3. StringCollection
  4. HashTable
Question 10 Multiple Choice (Single Answer)

Which method do you use to expllicitly to kill a user session?

  1. session.clear()
  2. session.dispose()
  3. Session.Abandon
  4. None
Question 11 Multiple Choice (Single Answer)

What’ is the sequence in which ASP.NET events are processed ?

  1. 1)Page_Init 2)Page_Load.3)Control events 4)Page_Unload event.
  2. 1)Page_Init 2)Page_Unload event..3)Control events 4)Page_Load
  3. 1)Page_Load 2)Page_Init 3)Control events 4)Page_Unload event.
  4. None
Question 12 Multiple Choice (Single Answer)

In ASP.NET the < authorization > section contain which of the following elements

  1. < allow >
  2. < deny>
  3. Both 1 and 2
  4. None
Question 13 True/False

Constructors have no return type, not even void.

  1. True
  2. False
Question 14 True/False

constructors can be abstract, final, native, static, or synchronized.

  1. True
  2. False
Question 15 True/False

constructors can have any of the access modifiers: public, protected, private.

  1. True
  2. False
Question 16 True/False

Constructors name is not same as their class name

  1. True
  2. False
Question 17 True/False

Constructors use "this"(keyword) to refer to another constructor in the same class with a different parameter list

  1. True
  2. False
Question 18 True/False

If a constructor uses this, it must not be in the constructor's first line

  1. True
  2. False
Question 19 True/False

Interfaces have constructors

  1. True
  2. False
Question 20 True/False

Every class in java has constructors including abstract classes

  1. True
  2. False