0

programming languages Online Quiz - 22

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

Java is a programming language originally developed by

  1. Dennis Ritchie

  2. Edsger Dijkstra

  3. James Gosling

  4. Louis Pasteur


Correct Option: C
  1. Hello and world

  2. Foo and Bar

  3. i and j

  4. int and float


Correct Option: B

Amoeba operating system was developed by

  1. Linus Torvalds

  2. Dennis Ritchie

  3. Sun Microsystems

  4. Andrew S. Tanenbaum


Correct Option: D
  1. Donald D. Chamberlin and Raymond F. Boyce

  2. Donald D. Chamberlin

  3. Raymond F. Boyce

  4. none


Correct Option: A

Why we use "Type Def" in C ?

  1. Modifying existing Data type.

  2. Used for defining type of data type used.

  3. Creating new data type names

  4. Not a valid key word


Correct Option: A

"typedefs" used for data types are not machine dependent.

  1. True

  2. False


Correct Option: B

"typedefs" used for data types are not machine dependent.

  1. True

  2. False


Correct Option: B

Consider the following code: int x, y, z; y = 1; z = 5; x = 0 - (++y) + z++; After execution of this, what will be the values of x, y and z?

  1. x = 4, y = 1, z = 5

  2. x = 3, y = 2, z = 6

  3. x = -7, y = 1, z = 5

  4. x = 4, y = 2, z = 6


Correct Option: B
Explanation:

To solve this question, the user needs to know the order of operations in C programming and the difference between pre-increment and post-increment operators.

First, let's break down the expression x = 0 - (++y) + z++:

  1. ++y is a pre-increment operator, which means it increments the value of y by 1 before the value is used in the expression. So, y becomes 2.
  2. z++ is a post-increment operator, which means it increments the value of z by 1 after the value is used in the expression. So, z remains 5 in this expression.
  3. The expression inside the parentheses is evaluated first, so ++y is evaluated to 2.
  4. Next, the multiplication and division are evaluated from left to right, but there are none in this expression.
  5. Finally, the addition and subtraction are evaluated from left to right.

So, 0 - (++y) evaluates to -2 and z++ evaluates to 5, therefore the whole expression evaluates to -2 + 5 = 3.

Therefore, the correct answer is:

The Answer is: B. x = 3, y = 2, z = 6

In the code below, what data types the variable x can have? byte b1 = 5; byte b2 = 10; x = b1 * b2;(A) byte (B) int (C) short (D) long (E) float (F) double

  1. (A), (B), (D) & (E)

  2. (B), (C) & (D)

  3. (B), (D), (E) & (F)

  4. (B), (D) & (E)

  5. (D) & (F)


Correct Option: C

AI Explanation

To determine the possible data types that the variable x can have, we need to understand the concept of type promotion and the rules for arithmetic operations in Java.

In the given code, the variables b1 and b2 are of type byte. When performing arithmetic operations on byte values, Java automatically promotes them to int before performing the operation. This is known as type promotion.

In the expression x = b1 * b2, the multiplication of b1 and b2 results in an int value. As a result, the variable x can store an int value.

Therefore, the correct answer is:

C. (B), (D), (E), and (F)

The variable x can have the data types int, long, float, and double.

Given the declarations boolean b; short x1 = 100, x2 = 200, x3 = 300; Which of the following statements are evaluated to true? (A) b = x1 * 2 == x2; (B) b = x1 + x2 != 3 * x1; (C) b = (x3 - 2*x2<0) || ((x3 = 400)<2**x2); (D) b = (x3 - 2*x2>0) || ((x3 = 400) 2*x2);

  1. (A), (B) & (C)

  2. (A), (C) & (D)

  3. (B) & (C)

  4. (A) & (C)

  5. (A) & (D)


Correct Option: D

AI Explanation

To determine which of the following statements are evaluated to true, let's evaluate each statement one by one:

Option A) b = x1 * 2 == x2; In this statement, x1 is multiplied by 2 and then compared with x2 using the equality operator. If the result of the comparison is true, then b will be assigned the value true. Otherwise, it will be assigned the value false.

Option B) b = x1 + x2 != 3 * x1; In this statement, x1 is added to x2 and the result is compared with 3 times x1 using the inequality operator. If the result of the comparison is true, then b will be assigned the value true. Otherwise, it will be assigned the value false.

Option C) b = (x3 - 2*x2<0) || ((x3 = 400)<2*x2); In this statement, there are two parts to the expression separated by the logical OR operator (||). The first part (x3 - 2*x2<0) checks if x3 - 2*x2 is less than 0. The second part ((x3 = 400)<2*x2) assigns the value 400 to x3 and then checks if the result is less than 2 raised to the power of x2. If either part of the expression evaluates to true, then b will be assigned the value true.

Option D) b = (x3 - 2*x2>0) || ((x3 = 400) 2*x2); In this statement, there are two parts to the expression separated by the logical OR operator (||). The first part (x3 - 2*x2>0) checks if x3 - 2*x2 is greater than 0. The second part ((x3 = 400) 2*x2) assigns the value 400 to x3 and then multiplies it by 2*x2. If either part of the expression evaluates to true, then b will be assigned the value true.

Now, let's evaluate each option:

Option A) (A), (B) & (C) Option B) (A), (C) & (D) Option C) (B) & (C) Option D) (A) & (C) Option E) (A) & (D)

Based on the evaluation of each statement, the correct answer is D) (A) & (C).

Statement (A) is evaluated to false because x1 * 2 is not equal to x2. Statement (B) is evaluated to true because x1 + x2 is not equal to 3 times x1. Statement (C) is evaluated to true because the first part of the expression (x3 - 2*x2<0) is false, but the second part of the expression ((x3 = 400)<2**x2) is true after assigning 400 to x3. Statement (D) is evaluated to false because the first part of the expression (x3 - 2*x2>0) is false, and the second part of the expression ((x3 = 400) 2*x2) is not a valid expression.

Therefore, the correct answer is (A) & (C).

  1. (A), (B) & (C)

  2. (A), (C) & (E)

  3. (A), (C) & (D)

  4. (A) & (E)

  5. (C) & (E)


Correct Option: B
Explanation:

To answer this question, the user needs to have a basic understanding of flow control statements in programming. Flow control statements are used to control the order in which statements are executed in a program. They can be used to make decisions, loop over sets of instructions, and interrupt the normal flow of execution.

Now, let's go through each option and explain why it is right or wrong:

A. (A), (B) & (C): Option A is incorrect because (B) break(); is not a valid flow control statement. (A) break; is a legal statement that is used to terminate a loop or switch statement. (C) continue outer; is also a legal statement that is used to skip to the next iteration of an outer loop. Therefore, option A is incorrect.

B. (A), (C) & (E): Option B is correct. (A) break; is a legal statement that is used to terminate a loop or switch statement. (C) continue outer; is also a legal statement that is used to skip to the next iteration of an outer loop. (E) return; is a legal statement that is used to exit a function and return a value. Therefore, option B is the correct answer.

C. (A), (C) & (D): Option C is incorrect because (D) continue(inner); is not a valid flow control statement. (A) break; is a legal statement that is used to terminate a loop or switch statement. (C) continue outer; is also a legal statement that is used to skip to the next iteration of an outer loop. Therefore, option C is incorrect.

D. (A) & (E): Option D is incorrect because (E) exit(); is not a valid flow control statement. (A) break; is a legal statement that is used to terminate a loop or switch statement. (E) return; is also a legal statement that is used to exit a function and return a value. Therefore, option D is incorrect.

E. (C) & (E): Option E is incorrect because it is missing a legal statement. (C) continue outer; is a legal statement that is used to skip to the next iteration of an outer loop. (E) return; is also a legal statement that is used to exit a function and return a value. Therefore, option E is incorrect.

The Answer is: B. (A), (C) & (E)

  1. Locale loc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.format(d));

  2. Locale loc = Locale.getDefault();System.out.println(loc.getDisplayCountry()+ “ “ + df.format(d));

  3. Locale bc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.setDateFormat(d));

  4. Locale loc = Locale.getDefault();System.out.println(loc.getDispbayCountry()+ “ “+ df.setDateFormat(d));


Correct Option: B

What is an Iterator ?

  1. Enables you to cycle through a collection in the forward direction only, for obtaining or removing elements

  2. just for loop

  3. while loop

  4. It is an class for storing objects


Correct Option: A
  1. The Set interface

  2. list stores elements in an ordered way but may contain duplicate elements

  3. List interface provides support for ordered collections of objects.

  4. All of the above


Correct Option: C

Which implementation of the List interface provides for the fastest insertion of a new element into the middle of the list?

  1. Vector

  2. Array List

  3. Linked List

  4. None of the above


Correct Option: C

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Vector - The Vector class in Java is synchronized, which means that access to its methods is thread-safe. However, this synchronization comes at a cost of performance. So, it is not the fastest implementation for inserting a new element into the middle of the list.

Option B) Array List - The ArrayList class in Java provides fast access to elements by index, but inserting an element into the middle of the list requires shifting all subsequent elements to make room for the new element. This can be a costly operation, especially if the list is large. Therefore, it is not the fastest implementation for inserting a new element into the middle of the list.

Option C) Linked List - The LinkedList class in Java is implemented as a doubly-linked list, where each element in the list contains references to the previous and next elements. This allows for efficient insertion and deletion of elements anywhere in the list, including the middle. Therefore, the Linked List implementation provides the fastest insertion of a new element into the middle of the list.

Option D) None of the above - Since option C (Linked List) is the correct answer, option D (None of the above) is incorrect.

The correct answer is C) Linked List. This option is correct because the Linked List implementation provides the fastest insertion of a new element into the middle of the list.

What is difference between array & arraylist?

  1. Array: can store primitive ArrayList: Stores object only

  2. Array: fix size ArrayList: resizable

  3. Array: can have multi dimensional ArrayList: can have multi dimensional

  4. Array: lang ArrayList: Collection framework


Correct Option: A,B,D

What is the Parent Class of ArraList?

  1. AbstractList

  2. List

  3. Array

  4. All of the Above


Correct Option: A

What are the constructors of ArrayList?

  1. ArrayList( )

  2. ArrayList(Collection c)

  3. ArrayList(int capacity)

  4. All of the Above


Correct Option: D
  1. Class

  2. Interface

  3. Abstract Class

  4. All of the above


Correct Option: A
- Hide questions