0

Java and C

Description: Java and C
Number of Questions: 15
Created by:
Tags: Java and C Java/Oracle /C/C++ Arrays and Pointers Operators and Expression Data Types Variables and Storage Classes
Attempted 0/15 Correct 0 Score 0

Which of the following accessibility modes in Java does not allow a method to access the data members from the non-subclass of the same package?

  1. Protected

  2. Public

  3. Private

  4. No modifier

  5. Virtual


Correct Option: C
Explanation:

This accessibility mode in Java does not allow a method to access the data members from the non-subclass of the same package.

Which of the following methods of Iterator class throws NoSuchElementException, if the next element does not exist?

  1. hasNext()

  2. next()

  3. remove()

  4. add()

  5. nextIndex()


Correct Option: B
Explanation:

This method of Iterator class throws NoSuchElementException, if there is not a next element.

Which of the following Exception classes in Java is used to deal with an exception, where an assignment to an array element is of incompatible type?

  1. ArithmeticException

  2. ArrayIndexOutOfBoundsException

  3. IllegalArgumentException

  4. ArrayStoreException

  5. IllegalStateException


Correct Option: D
Explanation:

This Exception class in Java is used to deal with the exception, where an assignment to an array element is of incompatible type.

Which of the following methods is used in Thread class to resume the execution of a Thread class?

  1. yield()

  2. setName()

  3. resume()

  4. isAlive()

  5. start()


Correct Option: C
Explanation:

This method is used to resume the execution of a Thread class.

Which of the following methods in Java is used to identify that the input argument is a letter?

  1. isDefined()

  2. isDigit()

  3. isLetter()

  4. isLowerCase()

  5. isSpaceChar()


Correct Option: C
Explanation:

This method is used to identify that the input argument is a letter, or not.

Which of the following methods in StringBuffer class concatenates two strings of different types to the end of the invoking string object?

  1. getChars()

  2. append()

  3. insert()

  4. reverse()

  5. delete()


Correct Option: B
Explanation:

This method in StringBuffer class concatenates two strings of different types to the end of the invoking string object.

Which of the following methods of Class returns the complete name of the class or interface of the invoking object?

  1. getSuperclass()

  2. isInterface()

  3. getName()

  4. toString()

  5. getClasses()


Correct Option: C
Explanation:

This method of Class returns the complete name of the class or interface of the invoking object.

Consider the following C statement. int a = 5; printf(a = %usizeof(a)); What would be the output of the above C code?

  1. a = 1

  2. a = garbage value

  3. a = 2

  4. Compiler error

  5. None of these


Correct Option: C
Explanation:

This is the correct option as the integer value occupies 2 bytes in the memory for storage.

Consider the following C statements. int i,alpha = 65; char ch[27]; for(i = 0;i<2;i++) { ch[i] = alpha; alpha = alpha + 1; } printf(!!!^!!!%s!!!^!!!,ch); What would be the output of the above C code?

  1. AB

  2. ABC

  3. 6566

  4. Compiler error

  5. 01


Correct Option: A
Explanation:

This is the correct option as the variable alpha is initialized with the value 65, which is an ASCII equivalent of 'A'. Since, 'for' loop lasts for the values 0 and 1, therefore the values 65 and 66 are initialized to the char array 'ch' that is nothing but ASCII value of 'A' and 'B'.

What would be the value of variables n and m in the following C code? int n, m; n = - 10; m = - n + 5; printf(!!!^!!!n = %dnm=%d!!!^!!!,n,m);

  1. n = - 10 m = - 5

  2. n = - 10 m = Garbage value

  3. n = - 10 m = 15

  4. n = 10 m = 5

  5. Compiler error


Correct Option: C
Explanation:

This is the correct option as the value of n = - 10 is already assigned, and m = - ( - n) + 5 will give the resultant value 15.

What would be the output of the following C statement? char ch; ch = 'A';ch = - ch + 'a'; printf(!!!^!!!ch = %d!!!^!!!,ch);

  1. ch = 162

  2. ch = 32

  3. ch = - 32

  4. Compiler error

  5. ch = 65


Correct Option: B
Explanation:

This is the correct option as the ASCII value of 'a' is 97 and 'A' is 65, and their difference is 32.

What would be the value of the following C code? float a; a = floor(6.523); printf(!!!^!!!a = 0.2f!!!^!!!,a);

  1. a = 6.00

  2. a = 6.60

  3. a = 7.00

  4. a = 6.70

  5. Compiler error


Correct Option: A
Explanation:

This is the correct option as floor() function returns the smallest integer value to the assigned value.

By default, the floating-point value displays ______________ digits after the decimal point.

  1. 3

  2. 2

  3. 6

  4. 4

  5. none of these


Correct Option: C
Explanation:

Floating-point values are displayed with 6 digits, after the decimal point.

Consider the following C statement. int a = 3,b = 2; a+ = b++; printf(!!!^!!!a = %d!!!^!!!,a); What would be the value of 'a'?

  1. a = 6

  2. a = 5

  3. a = 4

  4. a = 3

  5. Compiler error


Correct Option: B
Explanation:

This is the correct option as initial value of a is 3, and after addition with b, results in 5.

Which of the following methods in Thread class, checks that the thread is a daemon thread?

  1. join()

  2. isDaemon()

  3. activeCount()

  4. sleep()

  5. start()


Correct Option: B
Explanation:

This method checks that the thread is a daemon thread, or not.

- Hide questions