0

programming languages Online Quiz - 175

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

The keyword __________ is required to declare a class.

  1. public

  2. private

  3. class

  4. All of the above.


Correct Option: C

AI Explanation

To declare a class in most programming languages such as Java or C++, the keyword "class" is required.

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

Option A) public - The "public" keyword is used to specify the visibility level of class members (variables and methods), but it is not required to declare a class itself.

Option B) private - The "private" keyword is also used to specify the visibility level of class members, but it is not required to declare a class itself.

Option C) class - This option is correct because the "class" keyword is indeed required to declare a class. It is used to define a new class and its associated properties and methods.

Option D) All of the above - This option is incorrect because only Option C (class) is required to declare a class. Options A and B are used to specify the visibility level of class members, but they are not necessary for declaring a class itself.

Therefore, the correct answer is C) class.

class TempClass { int i; public void TempClass(int j) { int i = j; } } public class C { public static void main(String[] args) { TempClass temp = new TempClass(2); } }

  1. The program has a compilation error because TempClass does not have a default constructor.

  2. The program has a compilation error because TempClass does not have a constructor with an int argument.

  3. The program compiles fine, but it does not run because class C is not public.

  4. The program compiles and runs fine.


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) The program has a compilation error because TempClass does not have a default constructor.

This option is incorrect because the TempClass class does not require a default constructor. In the code provided, a parameterized constructor is defined in the TempClass class, which takes an int argument. Therefore, a default constructor is not needed.

Option B) The program has a compilation error because TempClass does not have a constructor with an int argument.

This option is correct because the code provided attempts to create an instance of the TempClass class with an int argument (2). However, the TempClass class only defines a parameterized constructor, which does not match the provided argument. As a result, there is a compilation error because there is no constructor in the TempClass class that accepts an int argument.

Option C) The program compiles fine, but it does not run because class C is not public.

This option is incorrect because the C class does not have any impact on the compilation or execution of the code. It is not being used or referenced in any way, so the accessibility of the C class does not affect the program's behavior.

Option D) The program compiles and runs fine.

This option is incorrect because there is a compilation error in the code. As explained in option B, the TempClass class does not have a constructor that accepts an int argument, and the code attempts to create an instance of TempClass with an int argument (2). Therefore, the program will not compile successfully.

The correct answer is B. The program has a compilation error because TempClass does not have a constructor with an int argument.

Given the declaration Circle x = new Circle(), which of the following statement is most accurate.

  1. x contains an int value

  2. x contains an object of the Circle type.

  3. x contains a reference to a Circle object.

  4. You can assign an int value to x.


Correct Option: C
Explanation:

To understand this question, the user needs to have basic knowledge of object-oriented programming and class declaration. In the given declaration Circle x = new Circle(), we are creating an object of the Circle class.

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

A. x contains an int value: This statement is incorrect because the Circle class does not contain int values. Therefore, x cannot contain an int value.

B. x contains an object of the Circle type: This statement is correct. The code is creating an object of the Circle class and assigning it to the variable x. Therefore, x contains an object of the Circle type.

C. x contains a reference to a Circle object: This statement is correct. In Java, objects are created on the heap and accessed through references. When we create an object of a class, we are creating an instance of that class on the heap and assigning a reference to that instance to a variable.

D. You can assign an int value to x: This statement is incorrect because x is declared as an object of the Circle class, not as an int. Therefore, you cannot assign an int value to x.

The correct answer is: C. x contains a reference to a Circle object.

Analyze the following code. public class Test { int x; public Test(String t) { System.out.println("Test"); } public static void main(String[] args) { Test test = null; System.out.println(test.x); } }

  1. The program has a syntax error because test is not initialized.

  2. The program has a syntax error because x has not been initialized.

  3. The program has a syntax error because you cannot create an object from the class that defines the object.

  4. The program has a syntax error because Test does not have a default constructor.

  5. The program has a runtime NullPointerException because test is null while executing test.x.


Correct Option: E

The default value for data field of a boolean type, numeric type, object type is ___________, respectively.

  1. true, 1, Null

  2. false, 0, null

  3. true, 0, null

  4. true, 1, null


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) true, 1, Null - This option is incorrect because the default value for a boolean type is false, not true. Also, the default value for a numeric type is 0, not 1. Lastly, the default value for an object type is null, not Null.

Option B) false, 0, null - This option is correct. The default value for a boolean type is false, the default value for a numeric type is 0, and the default value for an object type is null.

Option C) true, 0, null - This option is incorrect because the default value for a boolean type is false, not true. Also, the default value for a numeric type is 0, not 1. Lastly, the default value for an object type is null, not Null.

Option D) true, 1, null - This option is incorrect because the default value for a boolean type is false, not true. Also, the default value for a numeric type is 0, not 1. Lastly, the default value for an object type is null, not null.

The correct answer is B. This option is correct because the default value for a boolean type is false, the default value for a numeric type is 0, and the default value for an object type is null.

Analyze the following code: public class Test { public static void main(String[] args) { double radius; final double PI= 3.15169; double area = radius * radius * PI; System.out.println("Area is " + area); } }

  1. The program has syntax errors because the variable radius is not initialized.

  2. The program has a syntax error because a constant PI is defined inside a method.

  3. The program has no syntax errors but will get a runtime error because radius is not initialized.

  4. The program compiles and runs fine


Correct Option: A
Explanation:

To analyze the given code, we can see that it calculates the area of a circle using a radius and a constant value of PI.

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

A. The program has syntax errors because the variable radius is not initialized.

This option is partially correct. The variable radius is indeed declared but not initialized. Java requires variables to be initialized before they can be used in calculations. Therefore, the program will not compile due to this syntax error.

B. The program has a syntax error because a constant PI is defined inside a method.

This option is also partially correct. The constant PI is indeed defined inside the main method. However, this is not a syntax error. It is a common practice to define constants inside methods in Java. Therefore, this option is incorrect.

C. The program has no syntax errors but will get a runtime error because radius is not initialized.

This option is incorrect. The program has a syntax error because the variable radius is not initialized. Therefore, the program will not run at all, let alone produce a runtime error.

D. The program compiles and runs fine.

This option is incorrect because the program has a syntax error. It will not compile due to the uninitialized variable radius.

Therefore, the correct answer is:

The Answer is: A

Analyze the following code. public class Test { int x; public Test(String t) { System.out.println("Test"); } public static void main(String[] args) { Test test = new Test(); System.out.println(test.x); } }

  1. The program has a syntax error because System.out.println method cannot be invoked from the constructor.

  2. The program has a syntax error because x has not been initialized.

  3. The program has a syntax error because you cannot create an object from the class that defines the object.

  4. The program has a syntax error because Test does not have a default constructor.


Correct Option: D

Variables that are shared by every instances of a class are __________.

  1. public variables

  2. private variables

  3. instance variables

  4. class variables


Correct Option: D

AI Explanation

To answer this question, you need to understand the concept of class variables.

Option A) Public variables - This option is incorrect because public variables can be accessed and modified by any instance of a class, but they are not necessarily shared by every instance of the class.

Option B) Private variables - This option is incorrect because private variables are only accessible within the class itself and cannot be accessed or modified by instances of the class.

Option C) Instance variables - This option is incorrect because instance variables are unique to each instance of a class. Each instance has its own copy of the instance variables.

Option D) Class variables - This option is correct because class variables are shared by every instance of a class. They are declared at the class level and are accessed using the class name rather than an instance of the class.

The correct answer is D) class variables. This option is correct because class variables are shared by every instance of a class.

You should add the static keyword in the place of ? in Line ________ in the following code:

  1 public class Test {   2 private int age;  3   4 public ? int square(int n) {   5 return n * n;  6 }  7  8 public ? int getAge() {  9 }  10}

  1. in line 4

  2. in line 8

  3. in both line 4 and line 8

  4. none


Correct Option: A

SAS programming language is a

  1. 3rd generation programming language

  2. 4th generation programming language

  3. 5th generation programming language

  4. All of the above


Correct Option: B

SAS was conceived by

  1. Anthony J. Barr

  2. James Goodnight

  3. John Sall

  4. Caroll G. Perkins


Correct Option: A

Which of the following is not a SAS components

  1. Base SAS

  2. SAS Enterprise Business Intelligence Server

  3. SAS/ACCESS

  4. SAS Toolware Studio Administrator


Correct Option: D

First limited release of the SAS system

  1. SAS 60

  2. SAS 71

  3. SAS 10.0

  4. SAS 1S


Correct Option: B

SAS had been criticized for its poor graphics, In which version the graphics improved significantly.

  1. SAS 6

  2. SAS 7

  3. SAS 8

  4. SAS 9


Correct Option: B

Location of SAS's Worldwide Headquarters

  1. Cary,NC,USA

  2. Churchgate,Mumbai,India

  3. Ontario,Canada

  4. NYC,New York,USA


Correct Option: A

The goal of this product is to compete with Business Objects and Cognos' offerings.

  1. OLAP Cube Studio

  2. SAS/CONNECT

  3. Enterprise Guide

  4. SAS Enterprise Business Intelligence Server


Correct Option: D

What is SAS/SCL?

  1. Allows SAS to transparently share data with personal computer applications including MS Access and Microsoft Office Excel

  2. A plugin for Information Delivery Portal. It allows the user to create various graphics that represent a broad range of data. This allows a quick glance to provide a lot of information, without having to look at all the underlying data.

  3. Allows programmers to create and compile object-oriented programs.

  4. A client application that helps with building information maps.


Correct Option: C

Which of the following is not a group function?

  1. avg( )

  2. sqrt( )

  3. sum()

  4. max()


Correct Option: D

AI Explanation

To answer this question, we need to understand what group functions are in the context of databases.

Group functions, also known as aggregate functions, are functions that perform calculations on a set of values and return a single value. These functions are commonly used in SQL queries to summarize data. Some examples of group functions include AVG(), SUM(), and MAX().

Let's go through each option to determine which one is not a group function:

Option A) avg( ) - This option is a group function. The AVG() function calculates the average value of a set of values.

Option B) sqrt( ) - This option is not a group function. The SQRT() function calculates the square root of a single value, not a set of values. Therefore, this is the correct answer.

Option C) sum() - This option is a group function. The SUM() function calculates the sum of a set of values.

Option D) max() - This option is a group function. The MAX() function returns the maximum value from a set of values.

Therefore, the correct answer is B) sqrt( ) because it is not a group function.

- Hide questions