0

programming languages Online Quiz - 223

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

What are the two parts of a value of type double?

  1. significant digits

  2. length

  3. numerator

  4. denominator


Correct Option: A
Explanation:

To solve this question, the user needs to have a basic understanding of the double data type in programming.

The double data type is used to represent decimal numbers with a higher degree of precision than the float data type. It is a 64-bit data type, which means it contains 64 bits of information.

The two parts of a value of type double are:

A. significant digits: This refers to the number of digits in the value that are considered to be accurate. The more significant digits a value has, the more precise it is.

B. exponent: This refers to the power of 10 that the value is multiplied by. The exponent allows for a wider range of values to be represented than would be possible with a fixed number of digits.

C. numerator: This is not a part of a value of type double. The numerator is used in fractions to represent the top part of the fraction.

D. denominator: This is also not a part of a value of type double. The denominator is used in fractions to represent the bottom part of the fraction.

Therefore, the correct answer is:

The Answer is: A

  1. -1

  2. 0

  3. 4

  4. 8


Correct Option: A
Explanation:

To solve this question, the user needs to know what the indexOf() method does in Java. The indexOf() method returns the index of the first occurrence of a specified substring within a string, or -1 if the substring is not found.

In the given code fragment, the variable s is assigned the string "Foolish boy.", and the indexOf() method is called on this string with the argument "fool". Since the substring "fool" is not present in the original string (due to the capital letter 'F' in the string), the indexOf() method returns -1.

Therefore, the correct answer is:

The Answer is: D. -1

What is the value of k after the following code fragment? int k = 0; int n = 12 while (k < n) { k = k + 1; }

  1. O

  2. 11

  3. 12

  4. -3


Correct Option: C
Explanation:

To solve this question, the user needs to understand the basic control flow of the while loop and the concept of variable assignment.

The code initializes the variable k to 0 and the variable n to 12. The while loop continues running as long as the value of k is less than the value of n. In each iteration of the loop, the value of k is incremented by 1.

Since the loop runs 12 times, the value of k will be incremented 12 times. Therefore, at the end of the loop, the value of k will be equal to 12.

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

A. O: This option is incorrect because the value of k is incremented 12 times, resulting in a final value of 12, not 0.

B. 11: This option is incorrect because the value of k is incremented 12 times, resulting in a final value of 12, not 11.

C. 12: This option is correct. The value of k is incremented 12 times, resulting in a final value of 12.

D. -3: This option is incorrect because the loop increments the value of k by 1 each time, and the starting value of k is 0. Therefore, the value of k can never be negative.

The Answer is: C

Given the following code fragment:int A[];int i = 0;A = new int A[4];while (i < 4){A[i] = 10;i = i + 1;}

  1. 0

  2. 3

  3. 10

  4. UNKNOWN


Correct Option: C

AI Explanation

To answer this question, we need to understand the given code fragment and how it initializes and assigns values to an array.

The code fragment initializes an integer array A and sets the length of the array to 4 using A = new int[4];. Then, it enters a while loop that iterates as long as the variable i is less than 4.

Inside the while loop, the code assigns the value 10 to the elements of the array A at index i using A[i] = 10;. After that, it increments the variable i by 1 using i = i + 1;.

Let's go through each option to understand why it is correct or incorrect:

Option A) 0 - This option is incorrect because the code assigns the value 10 to the elements of the array A, not 0.

Option B) 3 - This option is incorrect because the variable i is incremented by 1 until it is no longer less than 4. Therefore, the value of i will be 4 after the while loop ends.

Option C) 10 - This option is correct because the code assigns the value 10 to each element of the array A using A[i] = 10;. Therefore, after the code execution, all elements of the array A will have the value 10.

Option D) UNKNOWN - This option is incorrect because the code fragment clearly assigns the value 10 to the elements of the array A. The value is not unknown.

The correct answer is Option C) 10. This option is correct because the code assigns the value 10 to each element of the array A using A[i] = 10;.

Given the following statement:huey.setDouble(8.0*32.2+1.0);What must be the data type of huey?

  1. DoubleField

  2. TextField

  3. IntField

  4. double


Correct Option: A

AI Explanation

To determine the data type of the variable "huey" in the given statement, let's analyze the expression used as an argument for the "setDouble()" method:

8.0 * 32.2 + 1.0

This expression involves multiplication and addition operations. When performing these operations, the data type of the resulting value depends on the data types of the operands involved.

In this case, both 8.0 and 32.2 are decimal numbers (floating-point numbers) represented using the double data type. The multiplication and addition operations will preserve the double data type.

Therefore, the resulting value of the expression is a double. Since the "setDouble()" method is used, we can conclude that the data type of the variable "huey" must be a DoubleField, which is the data type that can store double values.

So, the correct answer is:

A. DoubleField

The method setLabel can be used with what type of Object?

  1. DoubleField

  2. int

  3. TextField

  4. String


Correct Option: A

AI Explanation

To answer this question, you need to understand the method setLabel and the types of objects it can be used with.

The setLabel method is typically used to set the label or text associated with an object, such as a field or a button.

Let's go through each option to understand which one is correct:

Option A) DoubleField - This option is correct. The setLabel method can be used with a DoubleField object to set the label or text associated with it.

Option B) int - This option is incorrect. The setLabel method cannot be used with an int object as it is a primitive type and does not have any associated label or text.

Option C) TextField - This option is incorrect. The setLabel method cannot be used with a TextField object as it is typically used to set the text content of the field, not the label associated with it.

Option D) String - This option is incorrect. The setLabel method cannot be used with a String object as it is not an object that represents a specific UI element.

The correct answer is Option A) DoubleField. This option is correct because the setLabel method can be used with a DoubleField object to set the label or text associated with it.

A function is:

  1. An entity that receives inputs and outputs

  2. A way of storing values

  3. A sequence of characters enclosed by quotes

  4. A kind of computer


Correct Option: A

A signed data type has an equal number of non-zero positive and negative values available.TRUE/FALSE ?

  1. True

  2. False


Correct Option: A

AI Explanation

To answer this question, we need to understand the concept of signed data types.

In computer programming, a signed data type is a data type that can represent both positive and negative values. It uses a sign bit to indicate the sign of the value. The sign bit is typically the leftmost bit in the binary representation of the number.

For example, in a signed 8-bit data type, the range of values is from -128 to 127. The sign bit (the most significant bit) is 0 for positive numbers and 1 for negative numbers.

Now, let's consider the statement: "A signed data type has an equal number of non-zero positive and negative values available."

This statement is true. In a signed data type, the number of positive values is equal to the number of negative values. This is because the sign bit can represent one of two values (0 or 1), which determines whether the number is positive or negative.

Therefore, the correct answer is A) True.

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


Correct Option: A

class C1 { static class C2 { static int i1; } public static void main(String a[]) { System.out.println(C1.C2.i1); } } What is the result of attempting to compile and run the program?

  1. prints 0

  2. Compile time error

  3. Runtime exception

  4. None of the above


Correct Option: A

Which declare a compilable abstract class? (Choose all that apply.)

  1. A. public abstract class Canine { public Bark speak(); }

  2. B. public abstract class Canine { public Bark speak() { } }

  3. C. public class Canine { public abstract Bark speak(); }

  4. D. public class Canine abstract { public abstract Bark speak(); }


Correct Option: B
Explanation:

To solve this question, the user needs to know the syntax for declaring abstract classes in Java.

Option A: This is not a valid declaration of an abstract class, as it tries to define a method called speak that returns a Bark object, without defining the Bark class or interface. Additionally, it does not declare the class as abstract.

Option B: This is a valid declaration of an abstract class, as it declares the class as abstract using the abstract keyword, and defines an abstract method called speak that returns a Bark object. However, it does not provide an implementation for the method, which makes the class abstract.

Option C: This is not a valid declaration of an abstract class, as it tries to declare an abstract method within a non-abstract class. The class must be declared abstract for it to contain abstract methods.

Option D: This is not a valid declaration of an abstract class, as it tries to declare the class as abstract using the abstract keyword after the class name. The correct syntax is to use abstract before the class name.

Therefore, the correct answers are:

The Answer is: B.

Which are legal declarations?

  1. short x [];

  2. short [] y;

  3. short [5] x2;

  4. short z2 [5];

  5. short [] z [] [];

  6. short [] y2 = [5];


Correct Option: A,B,E

Which is true? (Choose all that apply. )

  1. A. "X extends Y" is correct if and only if X is a class and Y is an interface

  2. B. "X extends Y" is correct if and only if X is an interface and Y is a class

  3. C. "X extends Y" is correct if X and Y are either both classes or both interfaces

  4. D. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces


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) "X extends Y" is correct if and only if X is a class and Y is an interface - This option is incorrect. In Java, the keyword "extends" is used to indicate that a class is inheriting from another class or implementing an interface. Therefore, "X extends Y" is correct if X is a class and Y is either a class or an interface.

Option B) "X extends Y" is correct if and only if X is an interface and Y is a class - This option is incorrect. In Java, interfaces cannot directly inherit from classes. Instead, they can extend other interfaces. Therefore, "X extends Y" is incorrect if X is an interface and Y is a class.

Option C) "X extends Y" is correct if X and Y are either both classes or both interfaces - This option is correct. In Java, both classes and interfaces can extend other classes or interfaces. Therefore, "X extends Y" is correct if X and Y are either both classes or both interfaces.

Option D) "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces - This option is incorrect. As mentioned before, interfaces cannot directly extend classes in Java. Therefore, "X extends Y" is not correct if X is an interface and Y is a class.

The correct answer is C. "X extends Y" is correct if X and Y are either both classes or both interfaces.

Given: 1. class Voop { 2. public static void main(String [] args) { 3. doStuff(1); 4. doStuff(1, 2); 5. } 6. // insert code here 7. } Which, inserted independently at line 6, will compile? (Choose all that apply.)

  1. static void doStuff(int... doArgs) { }

  2. static void doStuff (int [] doArgs) { }

  3. static void doStuff(int doArgs...) { }

  4. static void doStuff(int... doArgs, int y) { }

  5. static void doStuff(int x, int... doArgs) { }


Correct Option: A,E

Given the following, 1. interface Base { 2. boolean m1 (); 3. byte m2(short s); 4. } Which code fragments will compile? (Choose all that apply.)

  1. interface Base2 implements Base { }

  2. abstract class Class2 extends Base { public boolean ml() { return true; } }

  3. abstract class Class2 implements Base { }

  4. abstract class Class2. implements Base { public boolean m1() { return (true); } }

  5. class Class2 implements Base { boolean m1( ) { return false; } byte m2(short s) { return 42; } }


Correct Option: C,D

Which declare a compilable abstract class? (Choose all that apply.)

  1. public abstract class Canine { public Bark speak(); }

  2. public abstract class Canine { public Bark speak() { } }

  3. public class Canine { public abstract Bark speak(); }

  4. public class Canine abstract { public abstract Bark speak(); }


Correct Option: B

Which is true? (Choose all that apply. )

  1. "X extends Y" is correct if and only if X is a class and Y is an interface.

  2. "X extends Y" is correct if and only if X is an interface and Y is a class.

  3. "X extends Y" is correct if X and Y are either both classes or both interfaces.

  4. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.


Correct Option: C

Given: 1. class Voop { 2. public static void main(String [] args) { 3. doStuff(1); 4. doStuff(1, 2); 5. } 6. // insert code here 7. } Which, inserted independently at line 6, will compile? (Choose all that apply.)

  1. static void doStuff(int... doArgs) { }

  2. static void doStuff (int [] doArgs) { }

  3. static void doStuff(int doArgs...) { }

  4. static void doStuff(int... doArgs, int y) { }

  5. static void doStuff(int x, int... doArgs) { }


Correct Option: A,E

Which are legal declarations? (Choose all that apply. )

  1. short x [];

  2. short [] y;

  3. short [5] x2;

  4. short z2 [5];

  5. short [] z [] [];

  6. short [] y2 = [5];


Correct Option: A,B,E

Can there be multiple tag in tiles-defs.xml?

  1. No

  2. Yes

  3. always present

  4. None of the above


Correct Option: A
- Hide questions