C# and Java Programming Fundamentals

Test your knowledge of C#/.NET and Java programming concepts including collections, access modifiers, object-oriented features, and code execution behavior

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

public class Test { public static void main(String... args) { for(int i = 2; i < 4; i++) for(int j = 2; j < 4; j++) if(i < j) assert i!=j : i; } }

  1. The class compiles and runs, but does not print anything
  2. The number 2 gets printed with AssertionError
  3. The number 3 gets printed with AssertionError
  4. compile error
Question 2 Multiple Choice (Single Answer)

What is the output for the below code ? public interface TestInf { int i =10; } public class Test { public static void main(String... args) { TestInf.i=12; System.out.println(TestInf.i); } }

  1. Compile with error
  2. 10
  3. 12
  4. Runtime Exception
Question 3 Multiple Choice (Single Answer)

What is the output for the below code ? public class Test { static { int a = 5; } public static void main(String[] args){ System.out.println(a); } }

  1. Compile with error
  2. 5
  3. 0
  4. Runtime Exception
Question 4 Multiple Choice (Single Answer)

What is the output for the below code ? class A { { System.out.print("b1 "); } public A() { System.out.print("b2 "); } } class B extends A { static { System.out.print("r1 "); } public B() { System.out.print("r2 "); } { System.out.print("r3 "); } static { System.out.print("r4 "); } } class C extends B { public static void main(String[] args) { System.out.print("pre "); new C(); System.out.println("post "); } }

  1. r1 r4 pre b1 b2 r3 r2 post
  2. r1 r4 pre b1 b2 post
  3. r1 r4 pre b1 b2 post r3 r2
  4. pre r1 r4 b1 b2 r2 r3 post
Question 5 Multiple Choice (Single Answer)

What is the output for the below code ? public class Test { public static void main(String... args) throws Exception { Integer i = 34; int l = 34; if(i.equals(l)){ System.out.println(true); }else{ System.out.println(false); } } }

  1. true
  2. false
  3. Compile Error
  4. Runtime Exception
Question 6 Multiple Choice (Single Answer)

A variable which is declared inside a method is called a________variable

  1. Serial
  2. Local
  3. Private
  4. Static
Question 7 Multiple Choice (Single Answer)

Two methods with the same name but with different parameters?

  1. Overloading
  2. Overriding
  3. Overridable
  4. Duplexing
Question 8 Multiple Choice (Single Answer)

Is there any errors in this -> EmployeeMgmt constructor: Public int EmployeeMgmt { emp_id = 100; }

  1. Return type
  2. No errors
  3. Formal parameters
  4. Name
Question 9 Multiple Choice (Single Answer)

If a class is using an interface....

  1. it must inherit the properties of the interface
  2. contain the same methods as the interface
  3. create an interface object
  4. all of the above
Question 10 True/False

Sealed Classes cannot be a base class?

  1. True
  2. False
Question 11 Multiple Choice (Single Answer)

What are the features of an abstract class?

  1. It contain instance variables
  2. It contain constructors
  3. It may extend another class
  4. All of the these
Question 12 Multiple Choice (Single Answer)

Features of Read only variables?

  1. It is allocated at compile time
  2. Declaration and initialization is separated
  3. It is allocated at runtime
  4. All of these
Question 13 Multiple Choice (Single Answer)

An Event has _____ as default return type?

  1. No return type for events
  2. Double
  3. Integer
  4. String
Question 14 Multiple Choice (Single Answer)

int keyword targets to which .Net type?

  1. System.Int8
  2. System.Int16
  3. System.Int32
  4. System.Int64
Question 15 Multiple Choice (Single Answer)

Difference between Convert.ToString() and ToString()

  1. Convert.ToString() handle null values but ToString() don't
  2. ToString() output as per format supplied
  3. Convert.ToString() only handle null values
  4. ToString() handle null values but Convert.ToString() don't
Question 16 Multiple Choice (Single Answer)

Boxing in .Net allows the user to convert?

  1. a interger type to double
  2. a reference type to a value type
  3. a value type to a reference type
  4. a double type to interger
Question 17 Multiple Choice (Single Answer)

Different ways a method can be overloaded in C#.NET?

  1. Different parameter data types
  2. Different number of parameters
  3. Different order of parameters
  4. All of these
Question 18 Multiple Choice (Single Answer)

Which of the following is incorrect about System.Text.StringBuilder and System.String?

  1. StringBuilder is more efficient when there is a large amount of string manipulation
  2. Strings are immutable, so each time a string is changed, a new instance in memory is created.
  3. StringBuilder is mutable; when you modify an instance of the StringBuilder class, you modify the actual string, not a copy
  4. Strings are mutable in .Net
Question 19 Multiple Choice (Single Answer)

What is accessibility modifier “protected internal”?

  1. It is available to classes that are within the same assembly and derived from the specified base class.
  2. It is available within the class definition
  3. It is the most permissive access level
  4. It is the least permissive access level
Question 20 Multiple Choice (Single Answer)

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

  1. HashTable
  2. ArrayList
  3. SortedList
  4. All of above