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
Questions
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; } }
- The class compiles and runs, but does not print anything
- The number 2 gets printed with AssertionError
- The number 3 gets printed with AssertionError
- compile error
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); } }
- Compile with error
- 10
- 12
- Runtime Exception
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); } }
- Compile with error
- 5
- 0
- Runtime Exception
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 "); } }
- r1 r4 pre b1 b2 r3 r2 post
- r1 r4 pre b1 b2 post
- r1 r4 pre b1 b2 post r3 r2
- pre r1 r4 b1 b2 r2 r3 post
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); } } }
- true
- false
- Compile Error
- Runtime Exception
A variable which is declared inside a method is called a________variable
- Serial
- Local
- Private
- Static
Two methods with the same name but with different parameters?
- Overloading
- Overriding
- Overridable
- Duplexing
Is there any errors in this -> EmployeeMgmt constructor: Public int EmployeeMgmt { emp_id = 100; }
- Return type
- No errors
- Formal parameters
- Name
If a class is using an interface....
- it must inherit the properties of the interface
- contain the same methods as the interface
- create an interface object
- all of the above
Sealed Classes cannot be a base class?
- True
- False
What are the features of an abstract class?
- It contain instance variables
- It contain constructors
- It may extend another class
- All of the these
Features of Read only variables?
- It is allocated at compile time
- Declaration and initialization is separated
- It is allocated at runtime
- All of these
An Event has _____ as default return type?
- No return type for events
- Double
- Integer
- String
int keyword targets to which .Net type?
- System.Int8
- System.Int16
- System.Int32
- System.Int64
Difference between Convert.ToString() and ToString()
- Convert.ToString() handle null values but ToString() don't
- ToString() output as per format supplied
- Convert.ToString() only handle null values
- ToString() handle null values but Convert.ToString() don't
Boxing in .Net allows the user to convert?
- a interger type to double
- a reference type to a value type
- a value type to a reference type
- a double type to interger
Different ways a method can be overloaded in C#.NET?
- Different parameter data types
- Different number of parameters
- Different order of parameters
- All of these
Which of the following is incorrect about System.Text.StringBuilder and System.String?
- StringBuilder is more efficient when there is a large amount of string manipulation
- Strings are immutable, so each time a string is changed, a new instance in memory is created.
- StringBuilder is mutable; when you modify an instance of the StringBuilder class, you modify the actual string, not a copy
- Strings are mutable in .Net
What is accessibility modifier “protected internal”?
- It is available to classes that are within the same assembly and derived from the specified base class.
- It is available within the class definition
- It is the most permissive access level
- It is the least permissive access level
What is the .NET collection class that allows an element to be accessed using a unique key?
- HashTable
- ArrayList
- SortedList
- All of above