0

programming languages Online Quiz - 150

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

What results from the following code? 1. class MyClass 2. { 3. void myMethod(int i) {System.out.println("int version");} 4. void myMethod(String s) {System.out.println("String version");} 5. public static void main(String args[]) 6. { 7. MyClass obj = new MyClass(); 8. char ch = 'c'; 9. obj.myMethod(ch); 10. } 11. }

  1. The code compiles and produces output: int version.

  2. Line 9 will not compile as there is no version of myMethod which takes a char as argument.

  3. An exception at line 9.

  4. Line 4 will not compile as void methods can't be overridden.


Correct Option: A

AI Explanation

To answer this question, we need to analyze the code snippet provided.

The code defines a class called MyClass with two methods:

  • myMethod(int i), which prints "int version"
  • myMethod(String s), which prints "String version"

In the main method, an object of MyClass is created on line 7. On line 8, a char variable ch is declared and assigned the value 'c'. On line 9, the myMethod method of the MyClass object is invoked with the char variable ch as an argument.

The correct answer is A) The code compiles and produces output: int version.

Explanation: When a method is called with an argument, Java looks for a matching method signature. In this case, there is no method with the exact signature myMethod(char c). However, the argument can be implicitly converted from char to int, which matches the signature of myMethod(int i). Therefore, the myMethod(int i) is invoked, and "int version" is printed as output.

What is the result when you compile and run the following code? public class ThrowsDemo { static void throwMethod() { System.out.println("Inside throwMethod."); throw new IllegalAccessException("demo"); } public static void main(String args[]) { try { throwMethod(); } catch (IllegalAccessException e) { System.out.println("Caught " + e); } } }

  1. Compile successfully, nothing is printed

  2. Runtime error

  3. Compilation error

  4. Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo


Correct Option: C

What is the result when you compile and run the following code? public class Test { public void method() { for(int i = 0; i < 3; i++) { System.out.print(i); } System.out.print(i); } }

  1. 0122

  2. 0123

  3. Compilation error

  4. None of these


Correct Option: C

What is the result when you compile and run the following code? public class Test { public void method() { for(int i = 0; i < 3; i++) { System.out.print(i); } System.out.print(i); } }

  1. 0122

  2. 0123

  3. Compilation error

  4. None of these


Correct Option: C

What will be printed when you execute the following code? class X { Y b = new Y(); X() { System.out.print("X"); } } class Y { Y() { System.out.print("Y"); } } public class Z extends X { Y y = new Y(); Z() { System.out.print("Z"); } public static void main(String[] args) { new Z(); } }

  1. z

  2. yz

  3. xyz

  4. yxyz


Correct Option: C

Which program creates the output data set Work.Temp2? SAS Data Set Work.Temp Obs Month1 Month2 Month3 1 10 20 30 2 11 22 33 3 55 66 77 4 100 200 300 SAS Data Set Work.Temp2 Obs Month Quarter1 Quarter2 Quarter3 Quarter4 1 Month1 10 11 55 100 2 Month2 20 22 66 200 3 Month3 30 33 77 300

  1. proc transpose data=work.temp out=work.temp2 prefix=Quarter; run;

  2. proc transpose data=work.temp out=work.temp2 name=Month prefix=Quarter; run;

  3. proc transpose data=work.temp out=work.temp2 prefix=Month name=Quarter; run

  4. proc transpose data=work.temp out=work.temp2 prefix=Month index=Quarter; run;


Correct Option: B

Which of the following is true about Proc Freq?

  1. For one-way frequency tables, PROC FREQ can compute statistics to test for equal proportions, specified proportions, or the binomial proportion

  2. PROC FREQ automatically displays the output in a report and can also save the output in a SAS data set.

  3. To estimate the strength of an association, PROC FREQ computes measures of association that tend to be close to zero when there is no association and close to the maximum (or minimum) value when there is perfect association.

  4. Statement 1 & 2

  5. Statement 2 & 3

  6. All of the above


Correct Option: F

Frequency distributions work best with variables that contain

  1. Continuous values

  2. Numeric Values

  3. Categorical Values

  4. Unique Values


Correct Option: C

Several SAS procedures produce frequency counts; only PROC FREQ computes chi-square tests for one-way to n-way tables and measures of association and agreement for contingency tables

  1. True

  2. False


Correct Option: B

When processing a FREQ procedure it is possible to run out of memory due to the fact that this procedure stores all of the value combinations in memory during processing. In order to prevent this error, try using Proc SORT to sort the data by as many variables as you can and also include those sorted variables in a BY statement in your Proc FREQ procedure. True or False?

  1. True

  2. False


Correct Option: B

By default, PROC FREQ creates a table of frequencies and percentages for which data set variables?

  1. Character variables

  2. Numeric Variables

  3. Both Numeric & Character Variables.

  4. None : Variable names must be specified.


Correct Option: C

Data asthma; input city Asthma count; datalines; 1 1 35 1 0 65 2 1 40 2 0 60 3 1 25 3 0 75 ; run; proc format; value asth 0= 'No Asthma' 1= 'Asthma' ; run; Which of the following code produce the output : Asthma Frequency Percent ---------------------------------- Asthma 100 33.33 No Asthma 200 66.67

  1. proc freq data=asthma ; weight count; tables asthma / nocum; format asthma asth.; run;

  2. proc freq data=asthma order = formatted ; weight count; tables asthma / nocum; format asthma asth.; run;

  3. proc freq data=asthma order = formatted ; weight count; tables asthma ; format asthma asth.; run;

  4. proc freq data=asthma order = formatted ; tables asthma / nocum; format asthma asth.; run;


Correct Option: B

What will be printed? use strict; my @a = (1, 2, 3); my %b = (2 => undef); for my $val (@a) { last if $b{$val}; } print $val;

  1. undef

  2. 0

  3. 1

  4. 2

  5. the code is ill-formed


Correct Option: E

What will be the value of $str after execution of the following code? my $str = '112133'; $str =~ s/(.)\1/$1/g;

  1. 112133

  2. 1233

  3. 1213

  4. 12133


Correct Option: C

my $val = 'x'; print ref($val); What is the output?

  1. SCALAR

  2. empty value

  3. STRING

  4. not a reference


Correct Option: B

What is the value of $match? my $txt = 'I am learning Perl'; my ($match) = $txt =~ /\s(.*)\s/;

  1. am learning

  2. I am learning Perl

  3. learning

  4. am

  5. none


Correct Option: A

The $_ variable

  1. holds the last pattern matched.

  2. holds the output field separator.

  3. identifies the current command line argument.

  4. none of the above is correct.


Correct Option: C

AI Explanation

To answer this question, you need to understand the purpose of the $_ variable in programming.

Option A) The $_ variable does not hold the last pattern matched. Instead, $&amp; or $MATCH is used to store the last pattern matched.

Option B) The $_ variable does not hold the output field separator. The output field separator is stored in the OFS variable, which is set using the ORS (Output Record Separator) variable.

Option C) The $_ variable does identify the current command line argument. In Perl and some other programming languages, $_ is a special variable that represents the default or "implicit" variable. It is often used in loops or in certain operations where an explicit variable is not specified.

Option D) The correct answer is option C. The $_ variable identifies the current command line argument.

Therefore, the correct answer is option C.

What is Perl?

  1. Practical Extraction and Report Language

  2. Practice for Exclusive and Report Language

  3. Practical Extraction and Report Learning

  4. Practical Exclusive and Report Language


Correct Option: A

The value of the expression $yards += 10

  1. is 10

  2. is true.

  3. cannot be determined from the information given.

  4. relies on which command line arguments were used.


Correct Option: C

Which of the following commands will turn a scalar ($str)into an array of characters?

  1. @a = split($str).

  2. @a = split(/\s/, $str).

  3. This task can be done in Perl but none of the above commands do it.

  4. @a = split(/./, $str).


Correct Option: C
- Hide questions