0

programming languages Online Quiz - 132

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

class C { public static void main (String[] a1) { System.out.print(a1[1] + a1[2] + a1[3]); }} What is the result of attempting to compile and run the program? java command A B C

  1. Prints: ABC

  2. Prints BC and Runtime Exception

  3. Prints: BCD

  4. Runtime Exception

  5. None of the above


Correct Option: B

class C{ static int s; public static void main(String a[]){ C obj=new C(); obj.m1(); System.out.println(s); } void m1(); { int x=1; m2(x); System.out.println(x+""); } void m2(int x){ x=x*2; s=x; }}

  1. prints 1,2

  2. prints 2,0

  3. prints 2,2

  4. compile time error

  5. Noneofthe above


Correct Option: A

class C { public static void main(String[] args) { int i1=1; switch(i1){ case 1: System.out.println("one"); case 2: System.out.println("two"); case 3: System.out.println("three"); }}} What is the result of attempting to compile and run the program?

  1. prints one two three

  2. prints one

  3. compile time error

  4. Runtime exception

  5. None of the above


Correct Option: A

AI Explanation

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

Option A) prints one two three - This option is correct because when the program is executed, the switch statement will match the value of i1 with case 1 and execute the code block starting from case 1. The code block includes the System.out.println("one") statement. After executing the code block for case 1, the program continues to execute the code blocks for case 2 and case 3 as there are no break statements present. Therefore, the output will be "one two three".

Option B) prints one - This option is incorrect because the program will execute the code blocks for case 1, case 2, and case 3 without any breaks. So, the output will be "one two three" and not just "one".

Option C) compile time error - This option is incorrect because there are no syntax errors in the provided code. Hence, it will compile successfully.

Option D) Runtime exception - This option is incorrect because there are no runtime errors in the provided code. The code will execute without any exceptions.

Option E) None of the above - This option is incorrect because the correct answer is Option A, which states that the program will print "one two three".

The correct answer is Option A. This option is correct because the program will print "one two three" when compiled and run.

Each element must be unique Duplicate elements must not replace old elements. Elements are not key/value pairs. Accessing an element can be almost as fast as performing a similar operation on an array. Which of these classes provide the specified features?

  1. LinkedList

  2. TreeMap

  3. HashMap

  4. HashSet


Correct Option: D

What is necessary for a programming language?

  1. For loop

  2. While loop

  3. Recursion

  4. All of these


Correct Option: C

Identify the true statement.

  1. For efficient program writing, we need syntax which is not strict

  2. For efficient program writing, we need syntax which is strict

  3. For quick compiler design, syntax is strict

  4. Syntax strictness and compiler design are not related


Correct Option: C

Programming is the job of ____

  1. Developer

  2. Maintenance Person

  3. Both developer and maintenance person

  4. Tester


Correct Option: C

Name the type of ABAP Dictionary table that has these characteristics: Same number of fields as the database table Same name as database table Maps 1:1 to database table

  1. Pooled

  2. Cluster

  3. Transparent

  4. View


Correct Option: C

AI Explanation

To answer this question, you need to have knowledge about the different types of ABAP Dictionary tables.

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

Option A) Pooled - This option is incorrect because a pooled table does not have the same number of fields as the database table.

Option B) Cluster - This option is incorrect because a cluster table does not have the same name as the database table.

Option C) Transparent - This option is correct because a transparent table has the same number of fields as the database table, the same name as the database table, and maps 1:1 to the database table.

Option D) View - This option is incorrect because a view is not a physical table and does not have the same number of fields as the database table.

The correct answer is C) Transparent. This option is correct because a transparent table matches all the characteristics mentioned in the question.

An event starts with an event keyword and ends with:

  1. Program execution

  2. END-OF-EVENT

  3. Another event keyword

  4. END-EVENT


Correct Option: C

Which of the following is NOT a required attribute when creating an ABAP program? A: Application B: Title C: Status D: Type

  1. A&C

  2. A&D

  3. C&D

  4. B&D


Correct Option: A

Coding two INITIALIZATION events will cause a syntax error.

  1. True

  2. False


Correct Option: A

AI Explanation

To answer this question, we need to understand how initialization events work in coding.

Initialization events are events that occur when a program or object is being initialized or created. These events are typically used to set initial values or perform any necessary setup before the program or object is ready to be used.

In most programming languages, including languages like Java, Python, and JavaScript, coding two initialization events will indeed cause a syntax error. This is because there can only be one initialization event for a program or object.

Having two initialization events would create ambiguity and confusion, as it would be unclear which initialization event should be executed first. Therefore, the programming language's syntax rules enforce having only one initialization event.

So, the correct answer is:

A) True - This option is correct because coding two initialization events will indeed cause a syntax error due to ambiguity and confusion.

B) False - This option is incorrect because coding two initialization events will cause a syntax error, as explained above.

When creating a transparent table in the ABAP Dictionary, which step automatically creates the table in the underlying database?

  1. Adding technical settings to the table

  2. Checking the table syntax

  3. Saving the table

  4. Activating the table


Correct Option: D

A field declared as type T has the following internal representation

  1. SSMMHH

  2. HHMMSS

  3. MMHHSS

  4. HHSSMM


Correct Option: B

If you use a RUN statement with a PROC SQL step

  1. SAS ignores the RUN statement, executes the statements as usual.

  2. Stop running due to error.

  3. Executes the code with a warning note

  4. Unexpected Result.


Correct Option: A

Complete the SELECT clause below to create a new column named Profit by subtracting the values of the column Cost from those of the column Price. select fruit,cost,price, ________________

  1. Profit=price-cost

  2. price-cost as Profit

  3. profit=price-cost

  4. Profit as price-cost


Correct Option: B

AI Explanation

To create a new column named Profit by subtracting the values of the column Cost from those of the column Price, you can use the following code:

SELECT fruit, cost, price, price - cost AS Profit

Option A) Profit = price - cost - This option is incorrect because it uses the wrong syntax for assigning a name to the new column. The correct syntax is "column_name AS alias_name".

Option B) price - cost AS Profit - This option is correct because it subtracts the value of the column Cost from the column Price and assigns the result to a new column named Profit.

Option C) profit = price - cost - This option is incorrect because it uses the wrong syntax for assigning a name to the new column. The correct syntax is "column_name AS alias_name".

Option D) Profit as price - cost - This option is incorrect because it uses the wrong syntax for subtracting the values of the column Cost from those of the column Price. The correct syntax is "column_name - column_name".

Therefore, the correct answer is B) price - cost as Profit.

Which PROC SQL query will remove duplicate values of MemberType from the query output, so that only the unique values are listed?

  1. proc sql nodup; select membertype from sasuser.frequentflyers;

  2. proc sql; select distinct(membertype) as MemberType from sasuser.frequentflyers;

  3. proc sql; select unique membertype from sasuser.frequentflyers group by membertype;

  4. proc sql; select distinct membertype from sasuser.frequentflyers;


Correct Option: D

AI Explanation

To answer this question, we need to understand how to remove duplicate values from a query output in PROC SQL.

Option A) proc sql nodup; select membertype from sasuser.frequentflyers; - This option is incorrect. The nodup keyword in PROC SQL is used to remove duplicate rows, not duplicate values within a single column. Therefore, this query will not remove duplicate values of MemberType.

Option B) proc sql; select distinct(membertype) as MemberType from sasuser.frequentflyers; - This option is incorrect. The distinct keyword is used to remove duplicate values from a column in the query output. This query will remove duplicate values of MemberType and provide only the unique values.

Option C) proc sql; select unique membertype from sasuser.frequentflyers group by membertype; - This option is incorrect. The unique keyword is not used in PROC SQL to remove duplicate values. This query will not remove duplicate values of MemberType.

Option D) proc sql; select distinct membertype from sasuser.frequentflyers; - This option is correct. The distinct keyword is used to remove duplicate values from a column in the query output. This query will remove duplicate values of MemberType and provide only the unique values.

The correct answer is Option D. This option is correct because it uses the distinct keyword to remove duplicate values of MemberType from the query output.

What happens if you use a GROUP BY clause in a PROC SQL step without a summary function?

  1. The step does not execute.

  2. The first numeric column is summed by default.

  3. The GROUP BY clause is changed to an ORDER BY clause.

  4. The step executes but does not group or sort data.


Correct Option: C

Which clause in the following program is incorrect? proc sql; select sex,mean(weight) as avgweight from company.employees company.health where employees.id=health.id group by sex;

  1. SELECT

  2. FROM

  3. WHERE

  4. GROUP BY


Correct Option: B

AI Explanation

To answer this question, we need to understand the structure and syntax of a SQL query. Let's go through each clause in the given program to identify the incorrect clause:

A. SELECT - This clause is used to specify the columns that you want to retrieve from the database. In the given program, the SELECT clause is correctly used to select the columns "sex" and "mean(weight) as avgweight".

B. FROM - This clause is used to specify the table or tables from which you want to retrieve data. In the given program, the FROM clause is used to specify the tables "company.employees" and "company.health".

C. WHERE - This clause is used to specify the conditions that must be met for the rows to be included in the result set. In the given program, there is no issue with the WHERE clause.

D. GROUP BY - This clause is used to group the rows in the result set based on one or more columns. In the given program, the GROUP BY clause is correctly used to group the rows by the "sex" column.

Based on the analysis, the incorrect clause in the given program is the FROM clause (option B). The correct answer is B.

You are creating a PROC SQL query that will list all employees who have spent (or overspent) their allotted 120 hours of vacation for the current year. The hours that each employee used are stored in the existing column Spent. Your query defines a new column, Balance, to calculate each employee’s balance of vacation hours. Which query will produce the report that you want?

  1. proc sql; select name, spent, 120-spent as calculated Balance from Company.Absences where balance <= 0

  2. proc sql; select name, spent, 120-spent as Balance from Company.Absences where calculated balance <= 0;

  3. proc sql; select name, spent, 120-spent as Balance from Company.Absences where balance <= 0;

  4. proc sql; select name, spent, 120-spent as calculated Balance from Company.Absences where calculated balance <= 0;


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) proc sql; select name, spent, 120-spent as calculated Balance from Company.Absences where balance &lt;= 0

This option is incorrect because it references a column balance in the where clause, which does not exist in the table.

Option B) proc sql; select name, spent, 120-spent as Balance from Company.Absences where calculated balance &lt;= 0;

This option is correct because it calculates the balance of vacation hours using the expression 120-spent and assigns it to the column Balance. It then filters the records where the calculated balance is less than or equal to zero.

Option C) proc sql; select name, spent, 120-spent as Balance from Company.Absences where balance &lt;= 0;

This option is incorrect because it references a column balance in the where clause, which does not exist in the table.

Option D) proc sql; select name, spent, 120-spent as calculated Balance from Company.Absences where calculated balance &lt;= 0;

This option is incorrect because it references a column calculated balance in the where clause, which is not defined in the select statement.

The correct answer is Option B. This option correctly calculates the balance of vacation hours and filters the records where the calculated balance is less than or equal to zero.

What is the purpose of the following statement ---- PROC SQL INOBS= 10;

  1. Restricts the number of rows (observations) that PROC SQL retrieves from any single source.

  2. Restricts the number of rows (observations) that PROC SQL can print.

  3. Directs the system to start reading the source from 10th observation.

  4. None of the above.


Correct Option: A
- Hide questions