0

programming languages Online Quiz - 55

Description: programming languages Online Quiz - 55
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0
  1. No,pointers can not be used here

  2. by using unsafe block

  3. by compiling using /unsafe option in command line only

  4. Both B and C

  5. None


Correct Option: D

Which of the Statements is true

  1. Static Variables are Set at RunTime

  2. Sealed classes cannot be Overriden

  3. finally' block executes only when exception occurs

  4. Both A and B

  5. Both B and C


Correct Option: D
  1. Adds a Reference to the parents class method

  2. it only hides the parent class method

  3. it overrides the parent class method

  4. None

  5. All the Above


Correct Option: B

First fully Object oriented language is:

  1. C++

  2. Java

  3. Simula

  4. None of the above


Correct Option: C

The member functions of a class can be defined outside the class using:

  1. extraction operator

  2. scope resolution operator

  3. insertion operator

  4. All the above


Correct Option: B

Which of the following exists in C++ ?

  1. virtual constructor

  2. virtual destructor

  3. both A and B

  4. None of the above


Correct Option: B

Reference to its own class can be accepted by:

  1. Simple constructor

  2. parameterized constructor

  3. copy constructor

  4. none of the above


Correct Option: C

Using pointers to call a function is called as:

  1. call by reference

  2. call by value

  3. call by address

  4. All the above


Correct Option: A

What will be the value of variable 'z' after execution of following code? int z; for(z=0;z<50;z++) {}

  1. 0

  2. 51

  3. 49

  4. 50


Correct Option: D

class PingPong2 { synchronized void hit(long n) { for(int i = 1; i < 3; i++) System.out.print(n + "-" + i + " "); } } public class Tester implements Runnable { static PingPong2 pp2 = new PingPong2(); public static void main(String[] args) { new Thread(new Tester()).start(); new Thread(new Tester()).start(); } public void run() { pp2.hit(Thread.currentThread().getId()); } } Which statement is true?

  1. The output could be 8-1 7-2 8-2 7-1

  2. The output could be 6-1 6-2 5-1 5-2

  3. The output could be 6-1 5-2 6-2 5-1

  4. The output could be 6-1 6-2 5-1 7-1


Correct Option: B

class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here 15. } Which code, inserted at line 14, allows the Sprite class to compile?

  1. Direction d = NORTH;

  2. Nav.Direction d = NORTH;

  3. Direction d = Direction.NORTH;

  4. Nav.Direction d = Nav.Direction.NORTH;


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) Direction d = NORTH; - This option is incorrect because the enum values are accessed using the enum name. In this case, the enum name is "Nav.Direction", so the correct syntax would be "Nav.Direction.NORTH".

Option B) Nav.Direction d = NORTH; - This option is incorrect because the enum values are accessed using the enum name, not just the enum constant. In this case, the correct syntax would be "Nav.Direction.NORTH".

Option C) Direction d = Direction.NORTH; - This option is incorrect because the enum values are accessed using the enum name. In this case, the enum name is "Nav.Direction", so the correct syntax would be "Nav.Direction.NORTH".

Option D) Nav.Direction d = Nav.Direction.NORTH; - This option is correct because it correctly accesses the enum constant "NORTH" from the enum "Direction" within the class "Nav". This allows the Sprite class to compile.

The correct answer is D. This option is correct because it uses the correct syntax to access the enum constant within the specified enum class.

Given: 11. class Mud { 12. // insert code here 13. System.out.println("hi"); 14. } 15. } And the following five fragments: public static void main(String...a) { public static void main(String.* a) { public static void main(String... a) { public static void main(String[]... a) { public static void main(String...[] a) { How many of the code fragments, inserted independently at line 12, compile?

  1. 0

  2. 1

  3. 2

  4. 3


Correct Option: D

AI Explanation

To determine how many of the code fragments, inserted independently at line 12, compile, let's analyze each option:

Option A) public static void main(String...a) - This option will not compile because the variable name in the main method parameter is missing. The correct syntax is "String[] a".

Option B) public static void main(String.* a) - This option will not compile because the syntax "String.* a" is not valid. The correct syntax is "String[] a".

Option C) public static void main(String... a) - This option will compile because it uses the correct syntax for the main method parameter, which is "String[] a".

Option D) public static void main(String[]... a) - This option will compile because it uses the correct syntax for the main method parameter, which is "String[] a".

Option E) public static void main(String...[] a) - This option will not compile because the syntax "String...[] a" is not valid. The correct syntax is "String[] a".

Therefore, out of the given options, options C) and D) will compile independently at line 12. So the correct answer is D) 3 options.

Which Man class properly represents the relationship "Man has a best friend who is a Dog"?

  1. class Man extends Dog { }

  2. class Man implements Dog { }

  3. class Man { private BestFriend dog; }

  4. class Man { private Dog bestFriend; }

  5. class Man { private Dog; }


Correct Option: D

Which two statements are true? (Choose two.)

  1. It is possible for more than two threads to deadlock at once.

  2. The JVM implementation guarantees that multiple threads cannot enter into a

  3. Deadlocked threads release once their sleep() method's sleep duration has expired.

  4. Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are

  5. It is possible for a single-threaded application to deadlock if synchronized blocks are

  6. . If a piece of code is capable of deadlocking, you cannot eliminate the possibility of


Correct Option: A,F

The notation for preprocessor directive is :

  1. $

  2. !

  3. @

  4. #


Correct Option: D

Given: 1. public class Blip { 2. protected int blipvert(int x) { return 0; } 3. } 4. class Vert extends Blip { 310-065 10 5. // insert code here 6. } Which five methods, inserted independently at line 5, will compile? (Choose five.)

  1. public int blipvert(int x) { return 0; }

  2. private int blipvert(int x) { return 0; }

  3. private int blipvert(long x) { return 0; }

  4. protected long blipvert(int x) { return 0; }

  5. protected int blipvert(long x) { return 0; }

  6. protected long blipvert(long x) { return 0; }


Correct Option: A,C,E,F

AI Explanation

To answer this question, we need to understand the concept of method overriding and access modifiers in Java.

In line 2, the method blipvert is defined in the Blip class with the protected access modifier. This means that the method can be accessed by any class within the same package or by any subclass, regardless of the package it belongs to.

In line 4, the Vert class extends the Blip class. This means that the Vert class inherits all the accessible members (fields and methods) of the Blip class, including the blipvert method.

We are asked to determine which methods, when inserted at line 5, will compile correctly.

Option A) public int blipvert(int x) { return 0; } This method has the same signature as the method in the Blip class, and it has a more accessible access modifier (public). Since a subclass is allowed to have a method with a more accessible access modifier, this method will compile.

Option B) private int blipvert(int x) { return 0; } This method has the same signature as the method in the Blip class, but it has a less accessible access modifier (private). A subclass is not allowed to have a method with a less accessible access modifier, so this method will not compile.

Option C) private int blipvert(long x) { return 0; } This method has a different parameter type (long) compared to the method in the Blip class (int). This is method overloading, not overriding. It will compile correctly.

Option D) protected long blipvert(int x) { return 0; } This method has the same signature as the method in the Blip class, but it has a different return type (long) compared to the method in the Blip class (int). This is method overloading, not overriding. It will compile correctly.

Option E) protected int blipvert(long x) { return 0; } This method has a different parameter type (long) compared to the method in the Blip class (int). This is method overloading, not overriding. It will compile correctly.

Option F) protected long blipvert(long x) { return 0; } This method has the same parameter type and return type as the method in the Blip class. It is an exact match for the overridden method, and it has the same or more accessible access modifier (protected). It will compile correctly.

Therefore, the five methods that will compile correctly when inserted at line 5 are: A, C, E, F.

Which of the following is used to receive a single string?

  1. gets

  2. getstring

  3. Both A and B

  4. None of the Above


Correct Option: A
- Hide questions