0

programming languages Online Quiz - 75

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

System.out.format("Pi is approximately %d.", Math.PI); What is the result?

  1. Compilation fails

  2. Pi is approximately 3

  3. Pi is approximately 3.141593

  4. An exception is thrown at runtime


Correct Option: D

AI Explanation

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

Option A) Compilation fails - This option is incorrect. The code will compile successfully as there are no syntax errors.

Option B) Pi is approximately 3 - This option is incorrect. The code uses the format specifier %d, which is used for integer values. Since Math.PI is a double value, using %d will result in incorrect output.

Option C) Pi is approximately 3.141593 - This option is incorrect. Although the output format is correct for a double value, the precision is not specified. The default precision for double is usually 6, so the output will be rounded to 3.141593.

Option D) An exception is thrown at runtime - This option is correct. The code uses the format specifier %d for an integer value, but Math.PI returns a double value. When trying to format the double value with %d, an exception will be thrown at runtime.

The correct answer is D. An exception is thrown at runtime because the format specifier %d is not compatible with the double value Math.PI.

NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(4); nf.setMinimumFractionDigits(2); String a = nf.format(3.1415926); String b = nf.format(2); Which statement is true about the result?

  1. The value of b is 2

  2. The value of b is 2.00

  3. The value of a is 3.141

  4. The value of a is 3.1415


Correct Option: B

public class Yippee2 { static public void main(String [] yahoo) { for(int x = 1; x < yahoo.length; x++) { System.out.print(yahoo[x] + " "); } } } and the command line invocation: java Yippee2 a b c What is the result?

  1. a b

  2. b c

  3. a b c

  4. Compilation fails


Correct Option: B

public static void main(String[] args) { String str = "null"; if (str == null) { System.out.println("null"); } else (str.length() == 0) { System.out.println("zero"); } else { System.out.println("some"); } } What is the result?

  1. null

  2. zero

  3. some

  4. Compilation fails


Correct Option: D

SELECT address1||','||address2||','||address2 "Adress" FROM employee;

  1. 1

  2. 2

  3. 3

  4. 0


Correct Option: C

AI Explanation

To answer this question, let's analyze the given SQL query:

SELECT address1||','||address2||','||address2 "Adress" FROM employee;

This query is selecting the concatenation of the address1, address2, and address2 columns from the employee table, separated by commas. The result is being aliased as "Address".

Now let's go through each option to determine the correct answer:

Option A) 1 - This option is incorrect because the query does not output the value 1.

Option B) 2 - This option is incorrect because the query does not output the value 2.

Option C) 3 - This option is correct. The query concatenates the values of address1, address2, and address2 columns with commas in between, and aliases it as "Address".

Option D) 0 - This option is incorrect because the query does not output the value 0.

Therefore, the correct answer is C) 3.

When an .aspx page is requested from the web server, the out put will be rendered to browser in following format.

  1. HTML

  2. XML

  3. WML

  4. JSP


Correct Option: A

To add a custom control to a Web form we have to register with.

  1. TagPrefix

  2. Name space of the dll that is referenced

  3. Assemblyname

  4. All of the above


Correct Option: D

AI Explanation

To add a custom control to a Web form, we need to register it with certain information. Let's go through each option to understand why it is correct or incorrect:

Option A) TagPrefix - This option is correct. When adding a custom control to a Web form, we typically use a TagPrefix to associate a prefix with the custom control. This prefix is used in the markup of the Web form to indicate that the control belongs to a specific namespace or assembly.

Option B) Namespace of the DLL that is referenced - This option is correct. When adding a custom control to a Web form, we need to reference the DLL that contains the control's code. The namespace of the DLL is important because it is used to identify the control and specify its location in the code.

Option C) Assemblyname - This option is correct. When adding a custom control to a Web form, we need to specify the assembly name of the DLL that contains the control's code. This is necessary for the Web form to locate and use the custom control.

Option D) All of the above - This option is correct. All of the options A, B, and C are required to successfully add a custom control to a Web form. We need to specify the TagPrefix, the namespace of the DLL, and the assembly name to properly register and use the custom control.

Therefore, the correct answer is D) All of the above. This option is correct because all the options mentioned (TagPrefix, namespace of the DLL, and assembly name) are required to register a custom control with a Web form.

What's the difference between Response.Write() andResponse.Output.Write()?

  1. Response.Output.Write() allows you to flush output

  2. Response.Output.Write() allows you to buffer output

  3. Response.Output.Write() allows you to write formatted output

  4. Response.Output.Write() allows you to stream output


Correct Option: C

The number of forms that can be added to a aspx page is.

  1. 1

  2. 2

  3. 3

  4. more than 3


Correct Option: A

How do you manage states in asp.net application

  1. Session object

  2. Application object

  3. View state

  4. All of the above


Correct Option: D

What is the program design method we learned in order to write Object Oriented Programs?

  1. Declare - Define - Use

  2. Public functions and private variables

  3. Top - Down programming

  4. Bottom - Up programming


Correct Option: C

Which is a logical abstract base class for a class called "footballPlayer"?

  1. Salary

  2. Sport

  3. Athlete

  4. Team


Correct Option: C

AI Explanation

To answer this question, we need to understand the concept of logical abstract base classes. A logical abstract base class represents a broader category or concept that other classes can inherit from.

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

Option A) Salary - This option is incorrect because "Salary" is not a logical abstract base class for a "footballPlayer". "Salary" represents a specific attribute or property of a football player, rather than a broader category or concept.

Option B) Sport - This option is incorrect because "Sport" is also not a logical abstract base class for a "footballPlayer". "Sport" represents a broader category that includes various sports, including football. However, it does not specifically represent a category that a "footballPlayer" would inherit from.

Option C) Athlete - This option is correct because "Athlete" is a logical abstract base class for a "footballPlayer". An athlete can participate in various sports, including football. By inheriting from the "Athlete" class, the "footballPlayer" class can inherit common attributes and behaviors associated with being an athlete.

Option D) Team - This option is incorrect because "Team" is not a logical abstract base class for a "footballPlayer". "Team" represents a specific entity or group that a football player can be a part of, rather than a broader category or concept.

The correct answer is C) Athlete. This option is correct because "Athlete" represents a logical abstract base class for a "footballPlayer".

A recursive function would result in infinite recursion, if the following were left out:

  1. Base case

  2. Recursive call

  3. Subtraction

  4. Local variable declarations


Correct Option: C

AI Explanation

To answer this question, we need to understand the concept of recursion in programming.

Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller subproblems.

In order for a recursive function to work correctly, it requires three essential components:

A. Base case: A base case is a condition that is used to terminate the recursion. It is the simplest form of the problem that does not require further recursive calls. Without a base case, the recursive function would continue calling itself infinitely, resulting in infinite recursion.

B. Recursive call: The recursive call is the step where the function calls itself with a smaller or simpler version of the problem. This allows the function to break down the original problem into smaller subproblems. Without the recursive call, the function would not be able to solve the problem recursively.

C. Subtraction: While subtraction is often used in recursive functions, it is not a requirement for a recursive function to work correctly. Recursive functions can perform various operations depending on the problem at hand, such as addition, multiplication, or string manipulation. The specific operation used in a recursive function depends on the problem being solved.

D. Local variable declarations: Local variable declarations are not required for a recursive function to work correctly. Recursive functions can use local variables to store intermediate results or perform calculations, but they are not essential for the recursion itself.

Based on the above explanations, the correct answer is C. If subtraction were left out, the recursive function could still work correctly as long as it includes a base case and recursive call.

  1. No

  2. Yes, but only if the two classes have the same name

  3. Yes, but only if the main program does not declare both kinds

  4. Yes, this is always allowed


Correct Option: D
  1. Inherits data members and member functions from base class

  2. Inherits constructors and destructor

  3. Object can access protected members with the dot operator

  4. Inherits data members and member functions from base class as well as Inherits constructors and destructor


Correct Option: D
  1. Polymorphism

  2. Inheritance

  3. Overloading

  4. None of these options


Correct Option: B
  1. Zero instance

  2. Multiple instance

  3. Both Zero instance & Multiple instance

  4. None of these options


Correct Option: C
  1. Serialization

  2. Persistence

  3. Marshalling

  4. None of these options


Correct Option: B
Explanation:

To solve this question, the user needs to understand the concept of object-oriented programming and the terminology used in it.

The state of an object refers to the values of its attributes or properties at a given point in time. Maintaining the state of an object means preserving these values so that they can be used later, even after the program has ended.

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

A. Serialization: Serialization refers to the process of converting an object into a format that can be stored or transmitted. While serialization can be used to maintain the state of an object, it is not the same thing as maintaining the state.

B. Persistence: This option is correct. Persistence refers to the act of preserving data beyond the lifetime of a program. In the context of object-oriented programming, persistence means maintaining the state of an object so that it can be used again later.

C. Marshalling: Marshalling is a technique used to transfer data between different applications or systems. While marshalling can be used to preserve the state of an object during transfer, it is not the same thing as maintaining the state.

D. None of these options: This option is incorrect because option B, Persistence, is the correct answer.

Therefore, The Answer is: B. Persistence.

- Hide questions