Programming Languages - Java and C Fundamentals

Test your knowledge of Java and C programming concepts including OOP principles, constructors, method overriding, and code compilation behavior.

20 Questions Published

Questions

Question 1 True/False

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

  1. True
  2. False
Question 2 True/False

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

  1. True
  2. False
Question 3 True/False

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

  1. True
  2. False
Question 4 True/False

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

  1. True
  2. False
Question 5 Multiple Choice (Single Answer)

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
Question 6 Multiple Choice (Single Answer)

A local variable with the same name as an instance variable

  1. shadowing
  2. Coupling
  3. Cohesion
  4. None of the above
Question 7 Multiple Choice (Single Answer)

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
Question 8 Multiple Choice (Single Answer)

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
Question 9 Multiple Choice (Single Answer)
  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
Question 10 Multiple Choice (Single Answer)

Look at the code below and select the correct answer:#include <stdio.h>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
Question 11 Multiple Choice (Single Answer)

See the code below and select the correct answer: #include<stdio.h> 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
Question 12 Multiple Choice (Single Answer)

See the code below and select the correct answer: #include<stdio.h> #include<conio.h> #include<string.h> 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
Question 13 True/False

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
Question 14 True/False

The code above will go into an infinite loop.

  1. True
  2. False
Question 15 True/False

The code below will go into infinite loop: #include<stdio.h> #include<conio.h> #include<string.h> 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
Question 16 True/False

Code: #include<stdio.h> #include<conio.h> #include<string.h> main() { int i=0, j=0; clrscr(); for (i=0; i<=5;i++) { for (j=0; j<i; j++) { printf ("1\t"); } printf("\n"); } getch(); return (0); } Output: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

  1. True
  2. False
Question 17 Multiple Choice (Single Answer)

Note the following code and then select the correct answer: #include<stdio.h> 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
Question 18 Multiple Choice (Single Answer)

Note the code below and select the correct answer: #include <stdio.h> 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
Question 19 True/False

static methods cannot be overridden to non-static methods.

  1. True
  2. False
Question 20 True/False

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

  1. True
  2. False