0

programming languages Online Quiz - 200

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

The following code creates one array and one string object. which object is eligible for garbage collection after the code executes? ... String[] students = new String[10]; String studentName = "Peter Parker"; students[0] = studentName; studentName = null; ...

  1. Array Object

  2. Neither Object

  3. String Objec

  4. Both of the Objects


Correct Option: B

Singleton class can have?

  1. More than one Object

  2. No Objects

  3. Only One Objects.

  4. Two Objects.


Correct Option: C

Identify the following. x. public final String getDetails(final File file, final String key) throws IOException y. getDetails(File, String)

  1. X is a method Signature and Y is a method Header

  2. Both X and Y is a method Header

  3. X is a method Header and Y is a method Signature

  4. Both X and Y is a method Signature


Correct Option: C

Static nested classes do not have access to

  1. Its non-static members

  2. Static members of the enclosing class

  3. Its Static members

  4. Non-Static members of the enclosing class


Correct Option: D

Facilities that are provided by Runtime class are:

  1. Reading data through key board

  2. Using system properties and environment variables

  3. Running non-java programs from within a java application.

  4. All of the Above

  5. None of the Above


Correct Option: D

Which of the following statements accurately describe the use of access modifiers within a class definition?

  1. They can be applied to both data & methods

  2. They must precede a class's data variables or methods

  3. They can follow a class's data variables or methods

  4. They can appear in any order

  5. They must be applied to data variables first and then to methods


Correct Option: A,B,D

AI Explanation

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

Option A) They can be applied to both data & methods - This option is correct because access modifiers can be applied to both data variables and methods within a class. Access modifiers such as public, private, and protected control the visibility and accessibility of these members.

Option B) They must precede a class's data variables or methods - This option is correct because access modifiers must be placed before the declaration of data variables or methods in a class. This ensures that the access level of these members is properly defined.

Option C) They can follow a class's data variables or methods - This option is incorrect because access modifiers cannot follow the declaration of data variables or methods. They must be placed before the declaration.

Option D) They can appear in any order - This option is correct because access modifiers within a class definition can appear in any order. However, it is generally good practice to follow a consistent ordering convention, such as placing them before the declaration.

Option E) They must be applied to data variables first and then to methods - This option is incorrect because access modifiers can be applied to data variables and methods in any order. There is no requirement to apply them to data variables first and then to methods.

The correct answer is A, B, D. These options accurately describe the use of access modifiers within a class definition.

What modifiers may be used with top-level class?

  1. Public

  2. Private

  3. Abstract

  4. Final

  5. Protected


Correct Option: A,C,D

What is the output of the following Program public class withoutmain{ static{ System.out.println("without the main method"); System.exit(0); } }

  1. Compile failure

  2. sucessfully compiled, but through exception in run time

  3. It runs sucessfuly and prints "without the main method"

  4. It runs sucessfuly, but No output.


Correct Option: C

AI Explanation

To answer this question, we need to understand how Java programs are executed.

In Java, the entry point of a program is the main() method. When a Java program is run, the Java Virtual Machine (JVM) looks for the main() method and starts executing the code from there.

In the given program, there is no main() method defined. Instead, there is a static block of code that is executed when the class is loaded. This static block contains the code System.out.println("without the main method"); which will print "without the main method" to the console.

Since this program does not have a main() method, it cannot be executed directly. However, if this class is used as a dependency in another program that does have a main() method, the static block will be executed when the class is loaded.

Therefore, the correct answer is:

C) It runs successfully and prints "without the main method"

Class C { public static void main(String[] args) { int[]a1[]=new int[3][3]; //3 int a2[4]={3,4,5,6}; //4 int a2[5]; //5 } } What is the result of attempting to compile and run the program ?

  1. compiletime error at lines 3,4,5

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception


Correct Option: B

class C1 { static interface I { static class C2 { } } public static void main(String a[]) { C1.I.C2 ob1=new C1.I.C2(); System.out.println("object created"); } } What is the result of attempting to compile and run the program?

  1. prints object created

  2. Compile time error

  3. Runtime Excepion

  4. None of the above


Correct Option: A

What is the output of following Program class C{ static int f1(int i) { System.out.print(i + ","); return 0; } public static void main (String[] args) { int i = 0; i = i++ + f1(i); System.out.print(i); } }

  1. Prints: 0,0

  2. Prints: 1,0

  3. Prints: 0,1

  4. Compile-time error


Correct Option: B

class c1{ public static void main(String a[]) { c1 ob1=new c1(); Object ob2=ob1; System.out.println(ob2 instanceof Object); System.out.println(ob2 instanceof c1); } } What is the result of attempting to compile and run the program?

  1. Prints true,false

  2. Print false,true

  3. Prints true,true

  4. compile time error


Correct Option: C

class C{ public static void main(String a[]) { int i1=9; int i2; if(i1>3) { i2=8; } System.out.println(i2); }}What is the result of attempting to compile and run the program?

  1. compile time error

  2. Runtim error

  3. prints 8

  4. prints 0


Correct Option: A

interface I { //1 public class Inner { ///2 Inner ( ) { System .out . println ( "Inner Created" ) ; } }; }; What is the result of attempting to compile and run the program?

  1. compile time error at line 1

  2. compile time error at line 2

  3. the code compiles fine

  4. none of the above


Correct Option: C

public class withoutmain{ static{ System.out.println("without the main method"); System.exit(0); } } What is the result of attempting to compile and run the program ?

  1. Compile failure

  2. sucessfully compiled, but through exception in run time.

  3. It runs sucessfuly and prints "without the main method"

  4. It runs sucessfuly, but No output.


Correct Option: C

Class C { public static void main(String[] args) { int[]a1[]=new int[3][3]; //3 int a2[4]={3,4,5,6}; //4 int a2[5]; //5 } } What is the result of attempting to compile and run the program ?.

  1. compiletime error at lines 3,4,5

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception


Correct Option: B

class C1 { static interface I { static class C2 { } } public static void main(String a[]) { C1.I.C2 ob1=new C1.I.C2(); System.out.println("object created"); } } What is the result of attempting to compile and run the program?

  1. prints object created

  2. Compile time error

  3. Runtime Excepion

  4. None of the above


Correct Option: A

class C{ static int f1(int i) { System.out.print(i + ","); return 0; } public static void main (String[] args) { int i = 0; i = i++ + f1(i); System.out.print(i); } } What is the result of attempting to compile and run the program?

  1. Prints: 0,0

  2. Prints: 1,0

  3. Prints: 0,1

  4. Compile-time error


Correct Option: B

Which version of Visual Studio first supported Linq for defining standard query operators

  1. VS2003

  2. VS2005

  3. VS2008

  4. VS2010


Correct Option: C

The process of applying redo log files during recovery operation is called

  1. rolling backward

  2. restore

  3. recovery

  4. rolling forward


Correct Option: D
- Hide questions