0

programming languages Online Quiz - 207

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

What's the difference between an Applet and an application ?

  1. An application is only available on Windows

  2. Applets can paint words, applications cannot.

  3. Applets are run over the web.

  4. None of the above.


Correct Option: C
  1. To add numbers together

  2. To keep track of data in the memory of the computer

  3. To print words on the screen

  4. To write Java


Correct Option: B

What is the proper way to declare a variable ?

  1. variableName variableType;

  2. variableName;

  3. variableType;

  4. variableType variableName;


Correct Option: D
  1. True or False

  2. Single characters

  3. Text

  4. All numbers


Correct Option: A

The following statements make “length” be what number ? int length; length = 4; length ++;

  1. 4

  2. 5

  3. 6

  4. 8


Correct Option: B
Explanation:

To solve this question, the user needs to understand the concept of variable assignment and increment operators.

In the given code, we first declare an integer variable named "length" and assign it a value of 4. Then we use the increment operator "++" to increase the value of "length" by 1.

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

A. 4: This option is incorrect because the value of "length" is changed by using the increment operator. Therefore, the final value of "length" is not the same as its initial value of 4.

B. 5: This option is correct. The initial value of "length" is 4, and then we increment it by 1 using the "++" operator. Therefore, the final value of "length" is 5.

C. 6: This option is incorrect because if we use two increment operators in succession, then the value of "length" would be 6. However, in this code, there is only one increment operator, so the final value of "length" is 5.

D. 8: This option is incorrect because there is no operation in the given code that would result in the value of "length" being 8. The initial value of "length" is 4, and then we increment it by 1, resulting in a final value of 5.

Therefore, the correct answer is:

The Answer is: B. 5

What is an assignment statement ?

  1. Adding a number to an int

  2. Assigning a multiplication

  3. Assigning a name to a variable

  4. Assigning a value to a variable


Correct Option: D

What will be the value of “num” after the following statements? int num; num = (5+4); num = num / 9; num = 12;

  1. 0

  2. 1

  3. 12

  4. 9


Correct Option: C

If you want your conditional to depend on two conditions BOTH being true, what is the proper notation to put between the two Boolean statements ?

  1. &

  2. &&

  3. ||


Correct Option: B

AI Explanation

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

Option A) & - This option is incorrect because the single ampersand (&) is a bitwise operator for AND in some programming languages, but it does not represent a logical AND operator for boolean conditions.

Option B) && - This option is correct because the double ampersand (&&) is the logical AND operator in many programming languages. It evaluates to true if and only if both conditions on its left and right sides are true.

Option C) | - This option is incorrect because the single vertical bar (|) is a bitwise operator for OR in some programming languages, but it does not represent a logical AND operator for boolean conditions.

Option D) || - This option is incorrect because the double vertical bar (||) is the logical OR operator in many programming languages. It evaluates to true if at least one of the conditions on its left and right sides is true, not both.

The correct answer is B) &&. This option is correct because the double ampersand (&&) is the proper notation to put between two boolean statements when you want your conditional to depend on both conditions being true.

Which of the following means that in order for the conditional to happen, either x must be less than 3 or y must be greater than or equal to 4 ?

  1. if ((x < 3) && (y > 4))

  2. if (x < 3 y >= 4)

  3. if ((x < 3) || (y > = 4))

  4. if ((x > 3) || (y < = 4))


Correct Option: C
  1. A new type of Applet

  2. A segment of code to be run a specified amount of times

  3. A segment of code to be run infinite times

  4. A segment of code to be run once


Correct Option: B

What is essential in making sure that your loop is not infinite ?

  1. That there is a Boolean statement somewhere in your code

  2. That your Boolean statement will at some point be false

  3. That your Boolean statement will at some point be true

  4. All of the above


Correct Option: B

Which is NOT a section of all types of loops ?

  1. Initialization

  2. Loop Body

  3. Test statement

  4. The word "while"


Correct Option: D
Explanation:

To solve this question, the user needs to know the basic structure of loops. Every loop has three main sections:

  1. Initialization
  2. Loop Body
  3. Test Statement

The initialization section is used to initialize the loop variable, while the test statement is used to evaluate a condition that determines whether the loop should continue or terminate. The loop body contains the code that is executed repeatedly until the test statement evaluates to false.

Option D is not a section of all types of loops. "While" is a keyword that is used to define a type of loop known as a "while loop". However, not all types of loops use the keyword "while". For example, the "for loop" uses a different syntax to define the loop.

Therefore, the correct answer is:

The Answer is: D

In a ‘for’ loop, what section of the loop is not included in the parentheses after “for” ?

  1. Initialization

  2. Loop Body

  3. Test statement

  4. Update


Correct Option: B

AI Explanation

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

Option A) Initialization - This option is incorrect because the initialization section is included in the parentheses after "for". It is typically used to initialize a counter variable.

Option B) Loop Body - This option is correct. The loop body is not included in the parentheses after "for". It is the block of code that is executed repeatedly as long as the test statement is true.

Option C) Test statement - This option is incorrect because the test statement is included in the parentheses after "for". It is used to check the condition for executing the loop body.

Option D) Update - This option is incorrect because the update section is included in the parentheses after "for". It is used to update the counter variable after each iteration of the loop.

The correct answer is B) Loop Body. This option is correct because the loop body is not included in the parentheses after "for".

What is a function in terms of Computer Science ?

  1. A group of code lines that performs a specific task

  2. A group of code lines that performs a whole program

  3. Something that contains an ‘init’

  4. The purpose of Java


Correct Option: A

What is the difference between private and public functions ?

  1. Public functions are free, you have to buy private ones

  2. Public functions are the only ones you can download

  3. Public functions can be used by anyone, private can only be used by other code in the class you are writing

  4. Public functions can’t be used


Correct Option: C
Explanation:

To answer this question, the user needs to know the basic concepts of functions in programming.

Public and Private functions are both used in classes in Object-Oriented Programming.

Public functions are those that can be accessed by any other code outside of the class in which they are defined. That means that any other code that creates an object of this class can use the public function.

On the other hand, Private functions can only be accessed by the code within the same class. No other code outside of that class can access the private function.

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

A. Public functions are free, you have to buy private ones: This option is incorrect because the cost of the function does not depend on whether it is public or private. The access level of a function does not affect its cost.

B. Public functions are the only ones you can download: This option is incorrect because both public and private functions can be downloaded. The downloadability of a function is not related to its access level.

C. Public functions can be used by anyone, private can only be used by other code in the class you are writing: This option is correct. Public functions are accessible by any other code outside of the class in which they are defined, whereas private functions can only be accessed by the code within the same class.

D. Public functions can’t be used: This option is incorrect because public functions can be used by other code outside of the class in which they are defined.

Therefore, the correct answer is:

The Answer is: C. Public functions can be used by anyone, private can only be used by other code in the class you are writing.

What does AWT stands for ?

  1. Advanced Window Toolkit

  2. Abstract window Toolkit

  3. Adjust Window Toolkit

  4. None of these


Correct Option: B

Given: class Hexy { public static void main(String[] args) { Integer i = 42; String s = (i<40)?"life":(i>50)?"universe":"everything"; System.out.println(s); } } What is the result?

  1. null

  2. life

  3. universe

  4. everything

  5. Compilation fails

  6. An exception is thrown at runtime


Correct Option: D

class Fork { public static void main(String[] args) { if(args.length == 1 | args[1] .equals("test")) { System.out.println ("test case"); } else { System.out.println("production " + args[0]); } }}And the command-line invocation:java Fork live2What is the result?

  1. test case

  2. production

  3. test case live2

  4. Compilation fails

  5. An exception is thrown at runtime


Correct Option: E

AI Explanation

To answer this question, let's go through the code and the command-line invocation step by step.

The code provided is a Java program that contains the main method. The main method takes an array of strings as a parameter (args). It checks if the length of the args array is equal to 1 and if the second element of the args array is equal to "test".

The command-line invocation is java Fork live2, which means that the args array will contain two elements: "live2" at index 0 and the length will be 1.

Now let's go through the options:

Option A) test case - This option is incorrect because the condition args.length == 1 evaluates to false since the length of the args array is 2. Therefore, the code will not print "test case".

Option B) production - This option is incorrect because the condition args.length == 1 evaluates to false. Therefore, the code will not enter the if block and will print "production live2".

Option C) test case live2 - This option is incorrect because the condition args.length == 1 evaluates to false. Therefore, the code will not print "test case", and the output will be "production live2".

Option D) Compilation fails - This option is incorrect because the code does not have any compilation errors.

Option E) An exception is thrown at runtime - This option is correct. In the condition args[1].equals("test"), it tries to access the second element of the args array (args[1]), but the args array only has one element (args[0]). Therefore, an ArrayIndexOutOfBoundsException will be thrown at runtime.

The correct answer is E. An exception is thrown at runtime.

Given: class Foozit { public static void main(String[] args) { Integer x = 0; Integer y = 0; for(Short z = 0; z < 5; z++) if((++x > 2) || (++y > 2)) X++ ; System.out.println(x + " " + y); } } What is the result?

  1. 5 1

  2. 5 2

  3. 5 3

  4. 8 1

  5. 8 2

  6. 8 3


Correct Option: E

Given: class Titanic { public static void main(String[] args) { Boolean bl = true; boolean b2 = false; boolean b3 = true; if((bl & b2) | (b2 & b3) & b3) System.out.print("alpha "); if((bl = false) | (b1 & b3) | (bl | b2)) System.out.print("beta "}; } } What is the result?

  1. beta

  2. alpha

  3. alpha beta

  4. Compilation fails

  5. No output is produced

  6. An exception is thrown at runtime


Correct Option: E

AI Explanation

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

Option A) beta - This option is incorrect because the code does not reach the second if statement, which is responsible for printing "beta".

Option B) alpha - This option is incorrect because the code does not reach the first if statement, which is responsible for printing "alpha".

Option C) alpha beta - This option is incorrect because the code does not reach either of the if statements, so no output is produced.

Option D) Compilation fails - This option is incorrect because the code is syntactically correct.

Option E) No output is produced - This option is correct because neither of the if statements evaluates to true, so no output is printed.

Option F) An exception is thrown at runtime - This option is incorrect because there are no exceptions thrown in the given code.

The correct answer is E. No output is produced. This option is correct because neither of the if statements evaluates to true, so no output is printed.

- Hide questions