0

programming languages Online Quiz - 17

Description: programming languages Online Quiz - 17
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

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


Correct Option: A

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;


Correct Option: C

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


Correct Option: D

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


Correct Option: C
  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.


Correct Option: D

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


Correct Option: B

Unboxing of a null refrence type will return null.

  1. a. true

  2. b. false

  3. c. an exception is thrown

  4. d. depends


Correct Option: C
  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


Correct Option: D
  1. a. Yes

  2. b. No

  3. c. Under certain conditions

  4. d. May be


Correct Option: B

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


Correct Option: B

A variable declared inside a method is called

  1. a. local variable

  2. b. global variable

  3. c. static variable

  4. d. private variable


Correct Option: A

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

  1. JAVA

  2. C

  3. ColdFusion

  4. HTML 5


Correct Option: C

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


Correct Option: D

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


Correct Option: C

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


Correct Option: D

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


Correct Option: B
- Hide questions