0

programming languages Online Quiz - 289

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

Which of these lists contains at least one word that is not a Java keyword?

  1. abstract, default, if, private, this

  2. do, implements, protected, boolean, throw

  3. case, extends, int, short, try

  4. import, break, double, exception, throws

  5. byte, else, instanceof, return, transient

  6. None of the above


Correct Option: D

class Identifiers { int i1; // 1 int _i2; // 2 int i_3; // 3 int #i4; // 4 int $i5; // 5 int %i6; // 6 int i$7; // 7 } Compile-time errors are generated at which lines?

  1. 1

  2. 2

  3. 3

  4. 4

  5. 5

  6. 6


Correct Option: D,F

Which of the following are true statements?

  1. Encapsulation is a form of data hiding.

  2. A tightly encapsulated class is always immutable.

  3. Encapsulation is always used to make programs run faster.

  4. Encapsulation helps to protect data from corruption.

  5. Encapsulation allows for changes to the internal design of a class while the public interface remains unchanged.


Correct Option: A,D,E
  1. A top-level class can not be called "tightly encapsulated" unless it is declared private.

  2. Encapsulation enhances the maintainability of the code.

  3. A tightly encapsulated class allows fast public access to member fields.

  4. A tightly encapsulated class allows access to data only through accessor and mutator methods.

  5. Encapsulation usually reduces the size of the code.

  6. A tightly encapsulated class might have mutator methods that validate data before it is loaded into the internal data model.


Correct Option: B,D,F
  1. The class is declared final.

  2. All local variables are declared private.

  3. All method parameters are declared final.

  4. No method returns a reference to any object that is referenced by an internal data member.

  5. None of the above


Correct Option: E

class GFC500 {private String name;} class GFC501 { private String name; private void setName(String name) {this.name = name;} private String getName() {return name;} } class GFC502 { private String name; public void setName(String name) {this.name = name;} public String getName() {return name;} } Which class is not tightly encapsulated?

  1. GFC501

  2. GFC502

  3. GFC503

  4. None of the above


Correct Option: D

class GFC506 {private String name;} class GFC507 extends GFC506 { String name; public void setName(String name) {this.name = name;} public String getName() {return name;} } class GFC508 extends GFC506 { private String name; public GFC508(String name) {setName(name);} public void setName(String name) {this.name = name;} public String getName() {return name;} } Which class is not tightly encapsulated?

  1. GFC506

  2. GFC507

  3. GFC508

  4. None of the above


Correct Option: B

Which of the following are command-line switches used to disable assertions in non-system classes?

  1. -disableassertions

  2. -disableAssertions

  3. -assertionsDisable

  4. -assertionsOn

  5. -assertionsOff


Correct Option: A

class A { void m1(int i) { int j = i % 3; switch (j) { case 0: System.out.print("0"); break; case 1: System.out.print("1"); break; default: assert j == 2; System.out.print(j); }} public static void main (String[] args) { A a = new A(); for (int i=5; i >= -1; i--) {a.m1(i);} }} Which statements are true?

  1. With assertions enabled it prints 210210-1 followed by an AssertionError message.

  2. With assertions enabled it prints 210210 followed by an AssertionError message.

  3. With assertions enabled it prints only 210210

  4. With assertions enabled it prints nothing.

  5. With assertions disabled it prints 210210-1

  6. With assertions disabled it prints only 210210


Correct Option: B,E

class C { String m1(int i) { switch (i) { case 0: return "A"; case 1: return "B"; case 2: return "C"; default: assert false; } } public static void main(String[] args) { C c = new C(); for (int i = 0; i < 4; i++) { System.out.print(c.m1(i)); }}} Which statements are true?

  1. With assertions enabled it prints ABC followed by an AssertionError message.

  2. With assertions disabled it prints ABC followed by an AssertionError message.

  3. Assertions should not be used within the default case of a switch statement.

  4. In this code example a throw statement must be used in place of the assert statement.

  5. Compile-time error


Correct Option: D,E

class C { int a, b, c; public void setA(int i) {a = i; assert validateC() : c;} public void setB(int i) {b = i; assert validateC() : c;} private boolean validateC() { return c > a + 2 * b; } public int m1(int i) { c = a + b + i; assert validateC() : c; return c; } public C(int i) { c = i; assert validateC() : c; } public static void main(String[] args) { C c = new C(251); c.setA(50); c.setB(100); }} Which statements are true?

  1. If assertions are not enabled at run time it prints an error message.

  2. If assertions are not enabled at run time it prints nothing.

  3. With assertions enabled it prints an error message.

  4. With assertions enabled it prints nothing.

  5. The assert statement is being used to check a class invariant--something that must be true about each instance of the class

  6. The assert statements are being used to check a precondition--something that must be true when the method is invoked.


Correct Option: B,D,E

What is the ouput of the following code snippet: $mystring = "[2004/04/13] The date of this article."; if($mystring =~ m/(\d)/) { print "The digit is $1"; }

  1. The digit is 3

  2. The digit is 2

  3. The digit is 1

  4. None of the above


Correct Option: B
  1. text always precedes the

  2. text always precedes the end of the end

  3. text always precedes the end of the

  4. None of the above


Correct Option: C

What is the output of the following code snippet: $mystring = "[2009/02/14] The date of this article."; if($mystring =~ m/(\d+)/) { print "$1"; }

  1. 14

  2. 02

  3. 2009

  4. Valentine's Day


Correct Option: C

a\Sz

  1. would match any three-character string starting with "a" and ending with "z" whose second character was not a space, tab or newline.

  2. the second character could be a letter, number or symbol

  3. would match any three-character string starting with "a" and ending with "z" whose second character was a newline

  4. None of the above


Correct Option: A,B

int (*p)(char *a)

  1. p is a function that accepts an argument which is a pointer to a character and returns a pointer to a 10 element integer array

  2. p is a pointer to a function that accepts an argument which is a pointer to a character and returns an integer quantity

  3. p is a function that accepts an argument which is a pointer to a character and returns an integer quantity

  4. None of the above


Correct Option: B

int *p(void)

  1. p is a function that accepts an argument which is a pointer to a character and returns an integer quantity

  2. p is a function that accepts an argument which is a pointer to a character and returns a pointer to an integer quantity

  3. p is a function that returns a pointer to an integer quantity

  4. None of the above


Correct Option: C

.{3,5}pentane

  1. will match "cyclopentane"

  2. will match "tri-pentane"

  3. will match "n-pentane"

  4. will match "neopentane"


Correct Option: A,B,D

int p(char *a[])

  1. p is a pointer to a function that accepts an argument which is a pointer to a character and returns an integer quantity

  2. p is a function that accepts an argument which is a pointer to a character array and returns an integer quantity

  3. p is a function that accepts an argument which is a pointer to a character and returns a pointer to a 10 element integer array

  4. None of the above


Correct Option: B
- Hide questions