wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

TEST3

Total questions: 26

Worksheet time: 14mins

Name
Class
Date
1.

class Test {

static int x = 10;

static {

x += 5;

}

public static void main(String[] args) {

x++;

System.out.println(x);

}

}

a)

A. 10

b)

B. 15

c)

C. 16

d)

D. 17

2.

class Test {

public static void main(String[] args) {

Integer a = 100;

Integer b = 100;

Integer c = 200;

Integer d = 200;

System.out.print(a == b);

System.out.print(" ");

System.out.print(c == d);

}

}

a)

A. true true

b)

B. false false

c)

C. true false

d)


D. false true

3.

Which statement is true?

a)

A. HashMap is synchronized

b)

B. ArrayList is thread-safe

c)

C. String is immutable

d)

D. StringBuilder is thread-safe

4.

String s = null;

System.out.println(s.length());

a)

A. IllegalArgumentException

b)

B. NullPointerException

c)

C. StringIndexOutOfBoundsException

d)

D. IOException

5.

#include <stdio.h>

int main() {

int a[] = {10, 20, 30};

printf("%d", *(a + 1));

return 0;

}

a)

A. 10

b)

B. 20

c)

C. Address

d)

D. Error

6.

Which is true?

a)

A. Array name is a pointer

b)

B. Pointer size depends on data type

c)

C. void* cannot store address

d)

D. char* pointer arithmetic increases by 1 byte

7.

#include <stdio.h>

int main() {

int x = 10;

if (x = 5)

printf("True");

else

printf("False");

return 0;

}

#include <stdio.h>

int main() {

int x = 10;

if (x = 5)

printf("True");

else

printf("False");

return 0;

}

a)

A. True

b)

B. False

c)

C. Error

d)

D. 5

8.

Which causes memory leak?

a)

A. Using malloc()

b)

B. Using free() twice

c)

C. Forgetting free()

d)

D. Using static variables

9.

#include <stdio.h>

int main() {

int x = 0;

while (x++ < 5);

printf("%d", x);

return 0;

}

a)

A. 5

b)

B. 6

c)

C. Infinite loop

d)

D. Error

10.

class Test {

public static void main(String[] args) {

main(null);

}

}

a)

A. StackOverflowError

b)

B. Prints nothing

c)

C. Compile-time error

d)

D. Runtime error

11.

What is the output of the following code?

int x = 10; if (x > 5) { x += 5; } System.out.println(x);

a)

C. 5

b)

B. 15

c)

D. 0

d)

A. 10

12.

Which of the following is false?

a)

D. The main method is static

b)

C. Java supports multiple inheritance through interfaces

c)

B. Primitive types can be null

d)

A. All objects in Java are created from classes

13.

What will be the output of the following code?

String str = "Hello"; str = str.concat(" World"); System.out.println(str);

a)

A. Hello

b)

B. Hello World

c)

C. HelloWorld

d)

D. Error

14.

What is the output of the following code?

int a = 5; int b = 10; System.out.println(a + b);

a)

D. 10

b)

A. 15

c)

B. 510

d)

C. 5

15.

Which of the following is true regarding Java exceptions?

a)

D. All exceptions are checked

b)

C. Errors are a type of exception

c)

B. Runtime exceptions must be caught

d)

A. Checked exceptions are unchecked

16.

What will be the output of the following code?

String str = "Java"; str = str.toLowerCase(); System.out.println(str);

a)

D. Error

b)

C. Java

c)

B. java

d)

A. JAVA

17.

. Which is true?

a)

A. malloc() initializes memory

b)

B. calloc() allocates contiguous memory

c)

C. realloc() frees old memory automatically

d)

D. free(NULL) causes error

18.

#include <stdio.h>

int main() {

printf("%d", 5["ABCDE"]);

return 0;

}

a)

A. A

b)

B. E

c)

C. Compile-time error

d)

D. Garbage

19.

What is the default join in SQL?

a)

A. LEFT JOIN

b)

B. RIGHT JOIN

c)

C. FULL JOIN

d)

D. INNER JOIN

20.

Which is not a programming paradigm?

a)

A. Procedural

b)

B. Object-Oriented

c)

C. Functional

d)

D. Sequential Memory

21.

Which factor most affects time complexity?

a)

A. Compiler

b)

B. Hardware

c)

C. Input size

d)

D. Programming language

22.

Which notation describes upper bound?

a)

A. Ω (Omega)

b)

B. Θ (Theta)

c)

C. O (Big-O)

d)

D. λ (Lambda)

23.

Which concept allows platform independence?

a)

A. Compiler

b)

B. Interpreter

c)

C. Virtual Machine

d)

D. Assembler

24.

Which OOPS principle focuses on what an object does, not how?

a)

A. Encapsulation

b)

B. Inheritance

c)

C. Polymorphism

d)

D. Abstraction

25.

Which feature violates strict encapsulation?

a)

A. Private members

b)

B. Getter/Setter

c)

C. Inheritance

d)

D. Abstraction

26.

Which type of inheritance causes diamond problem?

a)

A. Single

b)

B. Multilevel

c)

C. Hierarchical

d)

D. Multiple