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

How can pointers be used in C#

  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

What does 'new' keyword do when used as a modifier for a method (inheritance)?

  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

Given: 1. package test; 2. 3. class Target { 4. public String name = "hello"; 5. } What can directly access and change the value of the variable name?

  1. any class

  2. only the Target class

  3. any class in the test package

  4. any class that extends Target


Correct Option: C

A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing any functionality. If they implement the new design, which two OO principles will they be promoting?

  1. Looser coupling

  2. Tighter coupling

  3. Lower cohesion

  4. Higher cohesion


Correct Option: A

AI Explanation

To answer this question, you need to understand object-oriented (OO) principles and how they relate to software design.

Option A) Looser coupling - This option is correct because reducing the number of methods in an API can help promote looser coupling. Coupling refers to the degree of interdependency between classes or components in a system. By reducing the number of methods, the programmers are likely reducing the dependencies between classes, making them more independent and loosely coupled.

Option B) Tighter coupling - This option is incorrect because reducing the number of methods in an API does not promote tighter coupling. Tight coupling refers to a high degree of interdependency between classes or components. In this case, the programmers are trying to reduce the dependencies and promote loose coupling.

Option C) Lower cohesion - This option is incorrect because reducing the number of methods in an API does not promote lower cohesion. Cohesion refers to the degree to which the responsibilities of a class or component are related and focused. Reducing the number of methods may or may not affect the cohesion of the API, depending on the specific design changes made.

Option D) Higher cohesion - This option is incorrect because reducing the number of methods in an API does not promote higher cohesion. Similar to option C, cohesion refers to the degree of relatedness and focus in the responsibilities of a class or component. The impact on cohesion depends on the specific design changes made.

The correct answer is A) Looser coupling. By reducing the number of methods in the API, the programmers are promoting looser coupling between classes or components.

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.

What is the output of the following C program? main() { int a=10; int b; b=a++ + 20; printf("a=%d b=%d",a,b); }

  1. a=11 b=31

  2. a=10 b=30

  3. a=11 b=30

  4. None of the Above


Correct Option: C

AI Explanation

To determine the output of the given C program, let's go through the code step by step:

  1. Initialize the variable a with a value of 10.
  2. Declare the variable b.
  3. Assign the value of a (10) to b and then increment the value of a by 1 using the post-increment operator (a++).
    • After this step, a becomes 11 and b becomes 10.
  4. Print the values of a and b using printf() function with the format string "a=%d b=%d".
    • The values of a and b are 11 and 10 respectively.

Therefore, the correct answer is:

C. a=11 b=30

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