0

programming languages Online Quiz - 311

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

What is the maximum number of DD stmt a step can have?

  1. 100

  2. 15

  3. 300

  4. 255


Correct Option: D

If DISP=(,CATLG) which is the correct one?

  1. DISP=NEW,CATLG,CATLG

  2. DISP=OLD,DELETE,CATLG

  3. DISP=NEW,CATLG,DELETE

  4. DISP=OLD,CATLG,CATLG


Correct Option: A

What gets printed when the following program is compiled and run. Select the one correct answer. class test { public static void main(String args[]) { int i,j,k,l=0; k = l++; j = ++k; i = j++; System.out.println(i); } }

  1. 0

  2. 1

  3. 2

  4. 3


Correct Option: B

AI Explanation

To answer this question, let's go through each line of code and track the values of the variables:

  • int i,j,k,l=0;: This line declares four variables i, j, k, and l. l is initialized to 0.
  • k = l++;: The value of l is assigned to k first, and then l is incremented by 1. So, k becomes 0, and l becomes 1.
  • j = ++k;: k is incremented by 1 first, and then the value of k is assigned to j. So, k becomes 1, and j becomes 1.
  • i = j++;: The value of j is assigned to i first, and then j is incremented by 1. So, i becomes 1, and j becomes 2.
  • System.out.println(i);: The value of i is printed, which is 1.

Therefore, the correct answer is B) 1.

Which of the following are Java modifiers?

  1. public

  2. private

  3. friendly

  4. transient


Correct Option: A,B,D

AI Explanation

To answer this question, you need to understand Java modifiers.

Java modifiers are keywords that are used to specify the properties or characteristics of classes, methods, variables, and other program elements. They are used to control the visibility, accessibility, and behavior of these elements.

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

Option A) public - This option is correct. The "public" modifier is used to specify that a class, method, or variable is accessible to all other classes and code in the program.

Option B) private - This option is correct. The "private" modifier is used to specify that a class, method, or variable is only accessible within the same class.

Option C) friendly - This option is incorrect. There is no "friendly" modifier in Java. It seems like a typo or a misconception.

Option D) transient - This option is correct. The "transient" modifier is used to specify that a variable should not be serialized when an object is serialized.

The correct answer is A, B, and D. These options are correct because they are valid Java modifiers.

Which one does not have a ValueOf(String) method?

  1. integer

  2. boolean

  3. character

  4. long


Correct Option: C

Why might you define a method as native?

  1. to get to access hardware that Java does not know about

  2. to define a new data type such as an unsigned integer

  3. to write optimised code for performance in a language such as C/C++

  4. to overcome the limitation of the private scope of the method


Correct Option: A,C

AI Explanation

To answer this question, you need to understand the concept of native methods in Java.

Option A) to access hardware that Java does not know about - This option is correct because native methods allow Java programs to access hardware-specific functionalities or interact with the underlying operating system that Java does not natively support. This is useful when you need to perform low-level operations or interact with native libraries.

Option B) to define a new data type such as an unsigned integer - This option is incorrect. Defining new data types is not the purpose of native methods. Java does not support unsigned integers by default, but you can work around this limitation using other techniques such as bit manipulation or using larger data types.

Option C) to write optimized code for performance in a language such as C/C++ - This option is correct because native methods allow you to write performance-critical code in languages like C or C++ and then integrate it into your Java program. This can be done for specific parts of the code that require high efficiency or low-level operations.

Option D) to overcome the limitation of the private scope of the method - This option is incorrect. The private scope of a method is a language-level feature in Java, and using the native keyword does not affect the scope of a method. Native methods can be declared with any access modifier, including private, but their purpose is not related to overcoming the limitation of private scope.

Therefore, the correct answers are A and C. Native methods are used to access hardware-specific functionalities and write optimized code for performance in languages like C or C++.

Which option most fully describes will happen when you attempt to compile and run the following code public class MyAr{ public static void main(String argv[]) { MyAr m = new MyAr(); m.amethod(); } public void amethod(){ static int i; System.out.println(i); } }

  1. Compilation and output of the value 0

  2. Compile time error because i has not been initialized

  3. Compilation and output of null

  4. Compile time error


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 and output of the value 0 - This option is incorrect because the code will not compile.

Option B) Compile time error because i has not been initialized - This option is incorrect because the error in the code is not due to the initialization of variable i.

Option C) Compilation and output of null - This option is incorrect because the error in the code is not related to printing null.

Option D) Compile time error - This option is correct because there is a compile-time error in the code. The error occurs in the amethod() method where static int i; is declared. In Java, it is not allowed to declare local variables as static. Therefore, the code will fail to compile.

The correct answer is D. Compile time error.

Which one does not extend java.lang.Number?

  1. integer

  2. boolean

  3. character

  4. short


Correct Option: B,C

AI Explanation

To answer this question, we need to understand the hierarchy of the Java Number class and its subclasses.

The Java Number class is an abstract class that serves as the superclass for all numeric wrapper classes in Java, such as Integer, Float, and Double. These wrapper classes extend the Number class and provide specific implementations for various numeric types.

Let's go through each option to determine which one does not extend java.lang.Number:

Option A) Integer - This option is incorrect because the Integer class is a wrapper class that extends the Number class. Therefore, it does extend java.lang.Number.

Option B) Boolean - This option is correct because the Boolean class does not extend the Number class. The Boolean class is a wrapper class for the primitive boolean type, which is not a numeric type.

Option C) Character - This option is correct because the Character class does not extend the Number class. The Character class is a wrapper class for the primitive char type, which is also not a numeric type.

Option D) Short - This option is incorrect because the Short class is a wrapper class that extends the Number class. Therefore, it does extend java.lang.Number.

Therefore, the correct answer is Option B (Boolean) and Option C (Character). These options do not extend java.lang.Number.

Which of the following will compile correctly

  1. short myshort = 99S;

  2. String name = 'Excellent tutorial Mr Green';

  3. char c = 17c;

  4. int z = 015;


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) short myshort = 99S; - This option is incorrect because the suffix "S" is not a valid identifier for a short variable in Java. If you want to assign a value to a short variable, you can simply write "short myshort = 99;".

Option B) String name = 'Excellent tutorial Mr Green'; - This option is incorrect because single quotes ('') are used to represent characters in Java, not strings. To declare a string variable, you should use double quotes (""). Therefore, the correct statement would be "String name = "Excellent tutorial Mr Green";".

Option C) char c = 17c; - This option is incorrect because the suffix "c" is not a valid way to represent a character value in Java. If you want to assign a character value, you can use single quotes. For example, "char c = '17';".

Option D) int z = 015; - This option is correct because the value "015" is a valid octal (base-8) representation in Java. The leading zero indicates that the value is in octal format. Therefore, this statement will compile correctly.

The correct answer is D.

Which of the following are Java key words

  1. double

  2. Switch

  3. then

  4. instanceof


Correct Option: A,D

TreeMap class is used to implement which collection interface. Select the one correct answer

  1. SortedMap

  2. Tree

  3. Set

  4. SortedSet


Correct Option: A
Explanation:

To solve this question, the user needs to know what the TreeMap class is used for and which collection interface it implements.

The TreeMap class in Java is used to implement a map interface that sorts the keys in natural order. It provides an efficient means of storing key/value pairs in sorted order, making it useful for scenarios where you need to perform operations such as lookups, insertions, and deletions in a sorted collection.

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

A. SortedMap: This option is correct. TreeMap implements the SortedMap interface, which extends the Map interface and provides additional methods for retrieving and manipulating elements in a sorted order.

B. Tree: This option is incorrect. While TreeMap is implemented using a tree structure, it does not directly implement the Tree interface.

C. Set: This option is incorrect. TreeMap does not implement the Set interface, which is used for collections of unique elements.

D. SortedSet: This option is incorrect. TreeMap does not implement the SortedSet interface, which is used for sorted collections of unique elements.

The Answer is: A

Which of the following is the correct syntax for suggesting that the JVM performs garbage collection?

  1. System.free()

  2. System.setGarbageCollection()

  3. System.setGarbageCollector()

  4. System.gc()


Correct Option: D

AI Explanation

To answer this question, you need to understand how garbage collection works in Java. Garbage collection in Java is an automatic process performed by the Java Virtual Machine (JVM) to reclaim memory occupied by objects that are no longer in use.

The correct syntax for suggesting that the JVM performs garbage collection is:

D. System.gc()

Option A) System.free() - This option is incorrect because there is no method called free() in the System class in Java.

Option B) System.setGarbageCollection() - This option is incorrect because there is no method called setGarbageCollection() in the System class in Java. The JVM handles garbage collection automatically, so there is no need to set it explicitly.

Option C) System.setGarbageCollector() - This option is incorrect because there is no method called setGarbageCollector() in the System class in Java. The JVM handles garbage collection automatically, so there is no need to set it explicitly.

Option D) System.gc() - This option is correct because System.gc() is the correct syntax to suggest that the JVM performs garbage collection. However, it is important to note that calling System.gc() does not guarantee immediate garbage collection; it is merely a suggestion to the JVM.

The correct answer is D. System.gc() because it is the correct syntax to suggest that the JVM performs garbage collection.

True or False: You don’t need to specify a default value for an optional parameter

  1. True

  2. False


Correct Option: B

How many fields are maintained by the runtime by each instance of a reference type?

  1. One Field

  2. Two Fields

  3. Three Fields

  4. Four fields


Correct Option: B

Which of the following namespace provides classes that can be used to create and manipulate custom performance counters?

  1. System.NET.DNS

  2. System.Data.Common

  3. System.Diagnostics namespace

  4. none of the above


Correct Option: C

Which of the following happens when the FormBorderStyle property is set to None in VB.NET?

  1. borderless form is made

  2. The form cannot be moved

  3. Both A and B

  4. None of the Above


Correct Option: C

What is the significance of the option explicit statement when it is set to ON

  1. Specifies that any variable name is declared (with type) before use

  2. Specifies whether String should be compared as binary

  3. Specifies that variables should be intialized before use

  4. All of the above


Correct Option: A
Explanation:

To understand the significance of the option explicit statement when it is set to ON, the user needs to know about the Option Explicit statement in Visual Basic for Applications (VBA) programming language.

The Option Explicit statement is used to explicitly declare all variables in a VBA code module. When Option Explicit is turned on, the user must declare all variables before they are used in the code. If a variable is not declared, VBA generates a compile-time error.

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

A. Specifies that any variable name is declared (with type) before use - This option is correct. When Option Explicit is turned on, it requires you to declare all variables before they are used in the code. This helps prevent errors and ensures that all variables have a defined type.

B. Specifies whether String should be compared as binary - This option is incorrect. The Option Compare statement is used to specify how VBA compares strings, not the Option Explicit statement.

C. Specifies that variables should be initialized before use - This option is incorrect. Option Explicit only requires variables to be declared before use, not initialized.

D. All of the above - This option is incorrect. Option Explicit only specifies that variables must be declared before use, not any of the other options listed.

Therefore, the correct answer is:

The Answer is: A

Which of the following is used to check whether the Caps lock in keyboard is turned on or Not By using VB.Net 2005?

  1. If My.Computer.Keyboard.CapsLock = True Then

  2. If System.Computer.Keyboard.CapsLock = True Then

  3. Both A and B

  4. None of the Above


Correct Option: A
- Hide questions