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.
Questions
If you write a class with no constructors; the compiler will automatically supplies a no-argument(default)constructors
- True
- False
constructors can be overloaded but can't be overridden and constructors cannot be inherited.
- True
- False
The access modifier of default constructor is not same as class modifier
- True
- False
If a constructor uses super, it must use it in the first line; otherwise, the compiler will complain.
- True
- False
What is true from the following?
- "X extends Y" is correct if and only if X is a class and Y is an interface
- "X extends Y" is correct if and only if X and Y are either both classes or both interfaces
- "X extends Y" is correct if and only if X is an interface and Y is a class
- None of these
A local variable with the same name as an instance variable
- shadowing
- Coupling
- Cohesion
- None of the above
Select the true statement from the below choices
- Interface can extend one or more interfaces
- Interface can extend one or more class
- Interface cannot implement a class or interface
- All of the above
State which stament is true?
- Cohesionn is the OO principle most closely associated with hiding implementation details
- Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs
- None of these
- Cohesion is the OO principle most closely associated with making sure that a class is designed witha single well focussed principle
- 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?
- Class D has low Cohesion
- Class B has weak encapsulation
- Class A has weak encapsulation
- Class B has strong encapsulation
Look at the code below and select the correct answer:#include <stdio.h>main(){printf ("hello world");}
- Will not compile
- Will compile without error but not run
- Will compile with warnings but run ok
- Will compile with warnings, but not run
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); }
- Will not compile
- Will compile but not run
- Will give an output of 1
- Will give an output of 1.000000
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); }
- Will not compile
- Will compile with warning, and run
- Will compile but not run
- Will provide an output 1
The output of the above code is 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
- True
- False
The code above will go into an infinite loop.
- 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); }
- 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
- True
- False
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); }
- Will not compile
- Will compile with warnings, but run
- Will compile without warning, but not run
- Will give an output of 1
Note the code below and select the correct answer: #include <stdio.h> main() { printf ("hello world"); }
- Will not compile
- Will compile without error or warning and run ok
- Will compile without error or warning but not run
- Will compile with warning but run ok
static methods cannot be overridden to non-static methods.
- True
- False
we can not override a synchronized method as non-synchronized method.
- True
- False