0

programming languages Online Quiz - 216

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

Following test option may be used to check whether the stdin in a given script is a terminal

  1. [ -t 0 ]

  2. [ -t 1 ]

  3. [ -T 0 ]

  4. [ -T 1 ]


Correct Option: A

Given: class Clidders { public final void flipper() { System.out.println("Clidder"); } } public class Clidlets extends Clidders { public void flipper() { System.out.println("Flip a Clidlet"); super.flipper(); } public static void main(String [] args) { new Clidlets().flipper(); } } What is the result?

  1. Flip a Clidlet

  2. Flip a Clidder

  3. Flip a Clidder Flip a Clidlet

  4. Flip a Clidlet Flip a Clidder

  5. Compilation fails


Correct Option: E
  1. public abstract class Frob implements Frobnicate { public abstract void twiddle(String s){} }

  2. public abstract class Frob implements Frobnicate { }

  3. public class Frob extends Frobnicate { public void twiddle(Integer i) { } }

  4. public class Frob implements Frobnicate { public void twiddle(Integer i) { } }

  5. public class Frob implements Frobnicate { public void twiddle(String i) { } public void twiddle(Integer s) { } }


Correct Option: B,E

Given: class Clidder { private final void flipper() { System.out.println ("Clidder"); } } public class Clidlet extends Clidder { public final void flipper() { System.out.println("Clidlet"); } public static void main(String [] args) { new Clidlet().flipper(); } }

  1. Clidlet

  2. Clidder

  3. Clidder Clidlet

  4. Clidlet Clidder

  5. Compilation fails.


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) Clidlet - This option is correct because when the flipper() method is called on an instance of Clidlet, the method defined in the Clidlet class will be invoked. In this case, the flipper() method in Clidlet prints "Clidlet" to the console.

Option B) Clidder - This option is incorrect because the flipper() method in the Clidder class is marked as private, which means it cannot be accessed or overridden by any subclass. Therefore, the flipper() method in Clidder is not visible to the Clidlet class, and it will not be invoked.

Option C) Clidder Clidlet - This option is incorrect because the flipper() method in Clidder is not called or invoked in the main() method. Only the flipper() method in Clidlet is called.

Option D) Clidlet Clidder - This option is incorrect for the same reason as Option C. The flipper() method in Clidder is not called or invoked in the main() method.

Option E) Compilation fails - This option is incorrect because the code provided does not contain any compilation errors. The code will compile successfully.

The correct answer is Option A) Clidlet. This option is correct because when the flipper() method is called on an instance of Clidlet, the method defined in the Clidlet class will be invoked, which prints "Clidlet" to the console.

Given: class Uber { static int y = 2; Uber(int x) { this(); y = y * 2; } Uber() { y++; } } class Minor extends Uber { Minor() { super(y); y = y + 3; } public static void main(String [] args) { new Minor(); System.out.println(y); } } What is the result?

  1. 6

  2. 7

  3. 8

  4. 9

  5. Compilation fails.

  6. An exception is thrown.


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) 6 - This option is incorrect because the final value of y is not 6.

Option B) 7 - This option is incorrect because the final value of y is not 7.

Option C) 8 - This option is incorrect because the final value of y is not 8.

Option D) 9 - This option is correct.

Option E) Compilation fails - This option is incorrect because the code compiles without any errors.

Option F) An exception is thrown - This option is incorrect because the code does not throw any exceptions.

Now, let's analyze the code to determine the final value of y:

The Minor class extends the Uber class. When an object of the Minor class is created, the constructor Minor() is called.

Inside the Minor constructor, super(y) is called, which invokes the constructor Uber(int x) of the Uber class with the value of y.

In the Uber(int x) constructor, this() is called, which invokes the default constructor Uber() of the Uber class. Inside the Uber() constructor, y is incremented by 1.

After the this() call, y becomes 3.

Then, in the Uber(int x) constructor, y = y * 2 is executed, so y becomes 6.

Back in the Minor constructor, y = y + 3 is executed, so y becomes 9.

Finally, System.out.println(y) prints the value of y, which is 9.

Therefore, the correct answer is option D) 9.

Given the following, 1. class X { void dol() { } } 2. class Y extends X { void do2() { } } 3. 4. class Chrome { 5. public static void main(String [] args) { 6. X x1 = new X(); 7. X x2 = new Y(); 8. Y y1 = new Y(); 9. // insert code here 10. } Which, inserted at line 9, will compile? (Choose all that apply.)

  1. x2.do2( );

  2. (Y) x2. do2( );

  3. ((Y)x2).do2();

  4. None of the above statements will compile.


Correct Option: C
Explanation:

To solve this question, the user needs to know about method invocation and upcasting/downcasting in Java.

Line 6 creates a new instance of class X. Line 7 creates a new instance of class Y and assigns it to a reference variable of type X. Line 8 creates a new instance of class Y.

At line 9, we need to insert code that will compile. Since the reference variable x2 is of type X, it does not have access to the method do2() that is defined in class Y. However, we know that x2 refers to an object of class Y, which does have access to the do2() method. Therefore, we need to cast x2 to type Y in order to access the do2() method.

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

A. x2.do2( ); - This option is incorrect because the reference variable x2 is of type X, which does not have access to the do2() method that is defined in class Y.

B. (Y) x2. do2( ); - This option is incorrect because the cast operator (Y) is applied to the method call, not to the reference variable x2. This is not valid syntax.

C. ((Y)x2).do2(); - This option is correct. The cast operator is applied to the reference variable x2, casting it to type Y. This allows us to access the do2() method that is defined in class Y.

D. None of the above statements will compile. - This option is incorrect because option C will compile.

Therefore, the correct answer is:

The Answer is: C. ((Y)x2).do2();

  1. Woop is-a Hmpf and has-a zing.

  2. zing is-a Woop and has-a Hmpf.

  3. Hmpf has-a Woop and Woop is-a Zing.

  4. Woop has-a Hmpf and Woop is-a zing.

  5. Zing has-a Hmpf and Zing is-a Woop.


Correct Option: D
  1. It should be easy to write programs that process XML documents

  2. Optional features should be kept to a minimum, ideally zero

  3. XML documents should be human legible and reasonably clear

  4. None


Correct Option: B

The XML declaration is which of the following?

  1. Optional but makes a document more portable

  2. Highly discouraged by W3C standards

  3. Recommended for HTML programming only

  4. None


Correct Option: B

Attribute values must always be enclosed by single or double quotes

  1. parenthesis

  2. 'greater-than and less-than signs'

  3. single or double quotes

  4. brackets


Correct Option: C

AI Explanation

To answer this question, you need to understand how attribute values are represented in HTML or XML.

Option A) Parenthesis - This option is incorrect because attribute values are not enclosed by parenthesis in HTML or XML.

Option B) 'Greater-than and less-than signs' - This option is incorrect because greater-than and less-than signs (< and >) are used to enclose HTML or XML tags, not attribute values.

Option C) Single or double quotes - This option is correct. Attribute values in HTML or XML can be enclosed by either single quotes ('') or double quotes (""). For example, <img src="image.jpg"> or <p class="text">.

Option D) Brackets - This option is incorrect because brackets are not used to enclose attribute values in HTML or XML.

The correct answer is Option C. Attribute values must always be enclosed by single or double quotes.

Valid Options for printing the macro variable in %put statement are :

  1. ALL , AUTOMATIC , USER

  2. AUTO , SYS , LOCAL

  3. ALL , LOCAL ,USERDEFINED

  4. ALL , AUTO , GLOBAL


Correct Option: A

What is stored in the variable 'myvar' %let myvar=%str(%%%');

  1. %'

  2. %%'

  3. (apostrophe) '

  4. (percent) %


Correct Option: A

Executing the statement y=input(x,?? 2.); when variable x is having invalid data will cause the variable ERROR to have value ___ ?

  1. 1

  2. 0

  3. undefined

  4. any integer value


Correct Option: B

Which of the following TITLE statements correctly references the macro variable month?

  1. title "Total Sales for ’&month’ ";

  2. title "Total Sales for ’month’";

  3. title "Total Sales for &month";

  4. title Total Sales for "&month";


Correct Option: C

AI Explanation

To answer this question, you need to understand how to correctly reference a macro variable in a TITLE statement in SAS.

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

Option A) title "Total Sales for ’&month’ "; This option is incorrect because the macro variable month is not correctly referenced. The single quotes around &month are unnecessary and would cause the macro variable to be treated as text rather than a reference.

Option B) title "Total Sales for ’month’"; This option is incorrect because the macro variable month is not correctly referenced. The single quotes around the word "month" are unnecessary and would cause the word "month" to be treated as text rather than a reference.

Option C) title "Total Sales for &month"; This option is correct because the macro variable month is correctly referenced without any unnecessary quotation marks or single quotes.

Option D) title Total Sales for "&month"; This option is incorrect because the macro variable month is not correctly referenced. The double quotes around "&month" would cause the macro variable to be treated as text rather than a reference.

The correct answer is C. This option is correct because it correctly references the macro variable month without any unnecessary quotation marks or single quotes.

What value will these statements assign to the macro variable reptitle: %let area = "Southeast"; %let reptitle = * Sales Report for &area Area *;

  1. Sales Report for Southeast Area

  2. Sales Report for "Southeast" Area

  3. Sales Report for "Southeast" Area

    • Sales Report for "Southeast" Area *

Correct Option: D
  1. A macro variable can be defined and referenced anywhere in a SAS program except within data lines. within the data lines of a DATALINES statement.

  2. Macro variables are always user-defined, and their values remain constant until they are changed by the user.

  3. Macro variables are text strings that are independent of SAS data sets.

  4. The values of macro variables can be up to 65,534 characters long.


Correct Option: B

Which of the following statement is true

  1. Referencing a nonexistent macro variable results in a warning message. Referencing an invalid macro variable name results in an error message.

  2. Referencing a nonexistent macro variable results in a error message. Referencing an invalid macro variable name results in an warning message.

  3. Referencing a nonexistent macro variable and invalid macro variable name results in an error message.

  4. Referencing a nonexistent macro variable and invalid macro variable name results in an warning message.


Correct Option: A
- Hide questions