0
Alien head

programming languages Online Quiz - 20

Description: programming languages Online Quiz - 20
Number of Questions: 20
Created by:
Tags: programming languages

The modulus operator (%) in Java can be used only with variables of integer type.

  1. True

  2. False

Answer: 2

The "switch" selection structure must end with the default case.

  1. True

  2. False

Answer: 2

consider the statement "x = (a > b) ? a : b"; then the value of x is 27, if a = 18 and b = 27.

  1. True

  2. False

Answer: 1

Whenever the "&&" operator is used, such as in: exp1 && exp2 where exp1 and exp2 are boolean expressions, both the boolean expressions are not always evaluated.

  1. True

  2. False

Answer: 1

class base { base() { System.out.println("base"); } base(int i1) { } } class Super extends base { Super() { System.out.println("super"); super(1); } public static void main(String [] a) { base b1=new Super(); } }

  1. compile time error

  2. prints base and super

  3. prints super and base

  4. none of the above

Answer: 1

class C { public static void main(String a[]) { C c1=new C(); C c2=m1(c1); C c3=new C(); c2=c3; //6 anothermethod(); } static C m1(C ob1){ ob1 =new C(); return ob1; } } After line 6, how many objects are eligible for garbage collection?

  1. 1

  2. 2

  3. 3

  4. 4

  5. None of the above

Answer: 2

class C1 { static interface I { static class C2 { } } public static void main(String a[]) { C1.I.C2 ob1=new C1.I.C2(); System.out.println("object created"); } } What is the result of attempting to compile and run the program?

  1. prints object created

  2. Compile time error

  3. Runtime Excepion

  4. None of the above

Answer: 1
  1. interface I{ void f1(); // 1 public void f2(); // 2 protected void f3(); // 3 private void f4(); // 4 } which lines generate compile time errors?
  1. compiletime error at lines 1,2,3,4

  2. compiletime error at line 3

  3. compiletime error at line 1

  4. compiletime error at lines 3,4

  5. None of the above

Answer: 4

What happens when the following code is compiled and run. Select the one correct answer. for(int i = 1; i < 3; i++) for(int j = 3; j >= 1; j--) assert i!=j : i;

  1. The class compiles and runs, but does not print anything.

  2. The number 1 gets printed with AssertionError

  3. The number 2 gets printed with AssertionError

  4. The number 3 gets printed with AssertionError

  5. The program generates a compilation error.

Answer: 2

Which of the following cannot be inherited?

  1. private member

  2. Constructor

  3. Destructor

  4. Overloaded assignment operator

Answer: 2,3,4

Which of the following operators cannot be overloaded?

  1. ?:(Ternary Operator)

  2. .(member access)

  3. () (Paranthesis)

  4. ::(scope resolution)

Answer: 1,2,4

#include class NewInt { int num; public: NewInt(int n=0):num(n) {printf("cons\n");} int getInt() const {return num;} void setInt(int n){num =n;} ~NewInt(){printf("Dest\n");} }; int main() { NewInt a[5]; for(int i=0;i<=5;i++) a[i].setInt(i+10); for(int i=0;i<=5;i++) printf("%d\n",a[i].getInt()); return 0; } What does the above code snippet do?

  1. It creates an array of classes

  2. Gives compile time error

  3. It creates an array of objects

  4. It does nothing

Answer: 3

Storage area with associated semantics is called

  1. Class

  2. Constructor

  3. Object

  4. None

Answer: 3

public class test08 { public test08(Object o) { System.out.println("Object"); } public test08(double[] dArray) { System.out.println("double array"); } public static void main(String[] args) { new test08(null); } }

  1. Object

  2. double array

  3. Compile Error

  4. None of the above

Answer: 2

Destructors can be overloaded.

  1. True

  2. False

Answer: 2

class Dog { public static void bark() { System.out.print("woof "); }}class Alsation extends Dog { public static void bark() { }}public class Bark { public static void main(String args[]) { Dog woofer = new Dog(); Dog nipper = new Alsation(); woofer.bark(); nipper.bark(); }}What is the output

  1. woof

  2. woof woof

  3. Nothing will be printed as output

  4. None of the above

Answer: 2

The code in finally block will never get executed in the following program try { if (choice) { while (true) } else { system .exit(1): } }finally { codetocleanup(); }

  1. True

  2. False

Answer: 1

If you declare an object as constant, then every member of the object would be?

  1. variable

  2. same as if in noraml object

  3. constant

  4. none

Answer: 3

NullPointerException is a checked exception

  1. True

  2. False

Answer: 2

public class test08 { public static void main(String[] args) { try{ A a = new B(); a.show(); }catch (Exception e){ } } }class A{ void show() throws FileNotFoundException{ System.out.println("This is the super class"); }}class B extends A{ void show() throws Exception{ System.out.println("This is the inherited class"); }}What will be the output?

  1. This is the super class

  2. This is the inherited class

  3. Compile time error

  4. Run time exception

Answer: 3
+ View questions