Java and C# Programming Fundamentals

Test your knowledge of Java and C# programming concepts including abstract classes, interfaces, exception handling, access modifiers, and language-specific syntax.

20 Questions Published

Questions

Question 1 Multiple Choice (Multiple Answers)

The statement that is used to replace multiple if statements is

  1. a. The switch and case statement
  2. b. ternary operator
  3. c. nested if statement
  4. d. The #endif statement
Question 2 Multiple Choice (Multiple Answers)

The following code will generate a compiler error.

string GetAgePhrase(int age) {
    if (age > 60) return "Senior";
    if (age > 40) return "Middle-aged";
    if (age > 20) return "Adult";
    if (age > 12) return "Teen-aged";
    if (age > 4) return "Toddler";
}

Which of the following statements, inserted as the last line of the function, would solve the problem?

  1. a. continue;
  2. b. break;
  3. c. return "Infant";
  4. d. return 0;
Question 3 Multiple Choice (Multiple Answers)
static void Main(string[] args) {
    try {
        Console.WriteLine("Level 1");
        try {
            Console.WriteLine("Level 2");
            goto exit;
        } finally {
            Console.WriteLine("Level 2 Finished");
        }
    } finally {
        Console.WriteLine("Level 1 Finished");
    }
    exit: ;
}

What is the output?

  1. a. Leve1,Level 2,Level 1 Finished
  2. b. Level,Leve2,Leve 2 Finished
  3. c. Level 1,Level 2,Leve 2 Finished,Level 1 Finished
  4. d.Error
Question 4 Multiple Choice (Multiple Answers)

what is the default access specifier for a Top-level Class, which are not nested into other Classes?

  1. a. public
  2. b. private
  3. c. protected
  4. d. internal
Question 5 Multiple Choice (Multiple Answers)

Which statement is true about interface and abstract classes?

  1. a. An abstract class may only contain incomplete methods (abstract methods)
  2. b. An interface may contain complete or incomplete methods
  3. c. A class may inherit several interfaces, A class may inherit only one abstract class
  4. d. A class implementing an abstract class has to implement all the methods of the abstract class, but the same is not required in the case of an interface
Question 6 Multiple Choice (Multiple Answers)

If a method is marked as protected internal who can access it?

  1. a. Access is limited to the current assembly
  2. b. Access is limited to the containing class or types derived from the containing class.
  3. c. Access is limited to the containing type
  4. d. Access is limited to the current assembly or types derived from the containing class.
Question 7 Multiple Choice (Multiple Answers)

The default type of enum is integer and has a default value 1.

  1. a. true
  2. b. false
  3. c. sometimes
  4. d. depends
Question 8 Multiple Choice (Multiple Answers)

Unboxing of a null refrence type will return null.

  1. a. true
  2. b. false
  3. c. an exception is thrown
  4. d. depends
Question 9 Multiple Choice (Multiple Answers)

can we have protected element as a namespace member? eg namespace mine { protected class test { } }

  1. a. yes,all access specifiers are valid for namespace members
  2. b. No,only private access specifiers are possible
  3. c. No,implicitly all members are protected
  4. d. No,the namespace allows only public and internal elements as its members
Question 10 Multiple Choice (Multiple Answers)

Can multiple catch blocks be executed for single try block?

  1. a. Yes
  2. b. No
  3. c. Under certain conditions
  4. d. May be
Question 11 Multiple Choice (Multiple Answers)

Difference between const and readonly

  1. a. readonly value can be changed later
  2. b. const items are dealt at compile time however readonly is dealt at runtime
  3. c. const value can be changed later
  4. d. const items are dealt at runtime however readonly is dealt at compile time
Question 12 Multiple Choice (Multiple Answers)

A variable declared inside a method is called

  1. a. local variable
  2. b. global variable
  3. c. static variable
  4. d. private variable
Question 13 Multiple Choice (Single Answer)

In programming languages, which language's version name is also known as "Scorpio" ?

  1. JAVA
  2. C
  3. ColdFusion
  4. HTML 5
Question 14 Multiple Choice (Single Answer)

Which of the following declaration will compile without errors?
a)

public abstract class Digit {
    public abstract void print();
}

b)

public class Digit {
    public abstract void print();
}

c)

public abstract class Digit {
    public abstract void print(){};
}

d)

public abstract class Digit {
    public void print();
}

e)

public class Digit {
    public void print(){};
}
  1. a, b
  2. b, c
  3. a, d
  4. a, e
Question 15 Multiple Choice (Single Answer)

The following code contains a compilation error , what can be done to fix this error – independently?

abstract class AirPlane 
{ // line 1  
    abstract void fly(); // line 2  
    void land()
    {
        System.out.print("Landing..");
    }
}
class AirJet extends AirPlane 
{ // line 10  
    AirJet()
    {
        super(); // line 13  
    }
    void fly() 
    {
        System.out.print("Flying..");
    }
    abstract void land(); // line 20 
}

Please choose all the answers that apply:
a) Remove abstract from line 20 and add body to method land()

b) Declare class AirJet as abstract to at line 10

c) Remove super() call at line 13

d) Remove abstract at line 1 and line 2

  1. a, b
  2. a, c
  3. b, c
  4. c, d
Question 16 Multiple Choice (Single Answer)

What are the rules to implement an interface? Considering the following declaration for interface Convertable, which of the following code segments will compile?

public interface Convertable {
    int convertToInt();
    char convertToChar();
}

a)


class Digit implements Convertable {
public char convertToChar() {
return 0;
}
public int convertToInt() {
return 0;
}
}

b)


abstract class Digit implements Convertable {
int convertToInt();
char convertToChar();
}

c)


abstract class Digit implements Convertable {
public int convertToInt() {
return 0;
}
}

d)


abstract class Digit implements Convertable {
public int convertToInt() {
return 0;
}
char convertToChar();
}

e)

  class Digit implements Convertable {
int convertToInt() {
return 0;
return 0;
}
}

f)

interface Roundable extends Convertable {
int roundUp();
}

  1. a, b, c
  2. a, d, e
  3. a, c, f
  4. a, d, f
Question 17 Multiple Choice (Single Answer)

Which of the following variables is incorrectly declared?

public abstract interface Bouncable {
    int a = 0;
    public int b = 1;
    public static int c = 2;
    public static transient int d = 3;
    public final int e = 3;
    public static final int f = 3;
}
  1. c
  2. d
  3. e
  4. f
Question 18 Multiple Choice (Single Answer)

Three of the methods are incorrectly declared, which are they?

public abstract class Tester {
    public void test1();
    public final void test2() {};
    public static void test3() {};
    public abstract static void test4();
    public abstract final void test5();
}
  1. test1, test2 and test4
  2. test2, test4 and test5
  3. test1, test4 and test5
  4. test1, test2 and test3
Question 19 Multiple Choice (Single Answer)

Is the following declaration for interface Bendable correct and free of compilation error?

abstract interface Bendable { // line 1   

    final int x = 2009; // line 3    
    
    void method1() {}; // line 5 
}
  1. Yes, this is a correct and free of error declaration
  2. No, compilation error at line 1
  3. No, compilation error at line 3
  4. No, compilation error at line 5
Question 20 Multiple Choice (Single Answer)

What is the result of compiling and running the following code?

public class Tester {
    public static void main(String[] args) {
        System.out.print("1");
        try {
            return;
        } catch (Exception e) {
            System.out.print("2");
        } finally {
            System.out.print("3");
        }
        System.out.print("4");
    }
}
  1. 1234
  2. 13
  3. 1
  4. Compilation Error