0

programming languages Online Quiz - 252

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

If you write a class with no constructors; the compiler will automatically supplies a no-argument(default)constructors

  1. True

  2. False


Correct Option: A

constructors can be overloaded but can't be overridden and constructors cannot be inherited.

  1. True

  2. False


Correct Option: A

The access modifier of default constructor is not same as class modifier

  1. True

  2. False


Correct Option: A

If a constructor uses super, it must use it in the first line; otherwise, the compiler will complain.

  1. True

  2. False


Correct Option: A

What is true from the following?

  1. "X extends Y" is correct if and only if X is a class and Y is an interface

  2. "X extends Y" is correct if and only if X and Y are either both classes or both interfaces

  3. "X extends Y" is correct if and only if X is an interface and Y is a class

  4. None of these


Correct Option: B

A local variable with the same name as an instance variable

  1. shadowing

  2. Coupling

  3. Cohesion

  4. None of the above


Correct Option: A

Select the true statement from the below choices

  1. Interface can extend one or more interfaces

  2. Interface can extend one or more class

  3. Interface cannot implement a class or interface

  4. All of the above


Correct Option: A

State which stament is true?

  1. Cohesionn is the OO principle most closely associated with hiding implementation details

  2. Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs

  3. None of these

  4. Cohesion is the OO principle most closely associated with making sure that a class is designed witha single well focussed principle


Correct Option: D

AI Explanation

To answer this question, we need to understand the concept of cohesion in object-oriented programming (OO).

Cohesion refers to how closely the responsibilities and behaviors of a class or module are related. It is a measure of how well a class or module is focused on a single purpose or responsibility.

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

Option A) Cohesion is the OO principle most closely associated with hiding implementation details. This option is incorrect because hiding implementation details is more closely associated with the principle of encapsulation, not cohesion.

Option B) Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs. This option is incorrect because the principle described here is actually related to the concept of loose coupling, not cohesion.

Option C) None of these. This option is incorrect because there is a correct answer among the given options.

Option D) Cohesion is the OO principle most closely associated with making sure that a class is designed with a single well-focused purpose. This option is correct because cohesion is indeed the principle associated with ensuring that a class has a clear and specific responsibility.

Therefore, the correct answer is D) Cohesion is the OO principle most closely associated with making sure that a class is designed with a single well-focused principle.

1) Class A has a Class D 2)Methods in Class A use public methods in Class B 3)Methods in class C use public methods in class A 4)Methods in class A use variables in class C. What is most likely true?

  1. Class D has low Cohesion

  2. Class B has weak encapsulation

  3. Class A has weak encapsulation

  4. Class B has strong encapsulation


Correct Option: B

AI Explanation

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

Option A) Class D has low Cohesion - This option is not necessarily true based on the given information. Cohesion refers to the degree to which the elements within a module (class) belong together. The given information does not provide any indication of the cohesion of Class D.

Option B) Class B has weak encapsulation - This option is the correct answer. Encapsulation refers to the bundling of data and methods within a class, hiding the internal implementation details. The given information states that the methods in Class A use public methods in Class B. This implies that the internal implementation details of Class B are exposed and accessible to Class A, indicating weak encapsulation.

Option C) Class A has weak encapsulation - This option is not supported by the given information. The methods in Class A are using public methods in Class B, indicating a dependency on Class B, but it does not necessarily imply weak encapsulation in Class A.

Option D) Class B has strong encapsulation - This option is not supported by the given information. The methods in Class A are using public methods in Class B, indicating a dependency on Class B, but it does not necessarily imply strong encapsulation in Class B.

The correct answer is B) Class B has weak encapsulation. This option is correct because the given information states that the methods in Class A use public methods in Class B, indicating that the internal implementation details of Class B are exposed and accessible to Class A.

Look at the code below and select the correct answer:#include main(){printf ("hello world");}

  1. Will not compile

  2. Will compile without error but not run

  3. Will compile with warnings but run ok

  4. Will compile with warnings, but not run


Correct Option: C

See the code below and select the correct answer: #include main() { int i; printf ("enter integer: "); scanf ("%d",&i); printf ("You have entered: %f ", i); return (0); }

  1. Will not compile

  2. Will compile but not run

  3. Will give an output of 1

  4. Will give an output of 1.000000


Correct Option: B

See the code below and select the correct answer: #include #include #include main() { clrscr(); int i; printf ("enter integer: "); scanf ("%d",&i); printf ("You have entered: %d ", i); getch(); return (0); }

  1. Will not compile

  2. Will compile with warning, and run

  3. Will compile but not run

  4. Will provide an output 1


Correct Option: A

The output of the above code is 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

  1. True

  2. False


Correct Option: A

The code above will go into an infinite loop.

  1. True

  2. False


Correct Option: B

The code below will go into infinite loop: #include #include #include main() { int i=0, j=0; clrscr(); for (i=0; i<5;i++) { for (j=i; j<=0; j--) { printf ("1\t"); } printf("\n"); } getch(); return (0); }

  1. True

  2. False


Correct Option: B

Code: #include #include #include main() { int i=0, j=0; clrscr(); for (i=0; i<=5;i++) { for (j=0; j

  1. True

  2. False


Correct Option: A

Note the following code and then select the correct answer: #include main() { int i; printf ("enter integer: "); scanf ("%d",&i); printf ("You have entered: %f ", i); return (0); }

  1. Will not compile

  2. Will compile with warnings, but run

  3. Will compile without warning, but not run

  4. Will give an output of 1


Correct Option: C

Note the code below and select the correct answer: #include main() { printf ("hello world"); }

  1. Will not compile

  2. Will compile without error or warning and run ok

  3. Will compile without error or warning but not run

  4. Will compile with warning but run ok


Correct Option: D

static methods cannot be overridden to non-static methods.

  1. True

  2. False


Correct Option: A

we can not override a synchronized method as non-synchronized method.

  1. True

  2. False


Correct Option: B
- Hide questions