Search Header Logo
Java Programming

Java Programming

Assessment

Presentation

Computers

2nd Grade

Practice Problem

Hard

Created by

Dr. K

Used 1K+ times

FREE Resource

1 Slide • 22 Questions

1

Java Programming

Slide image

2

Multiple Choice

What is the range of short data type in Java?

1

-128 to 127

2

-32768 to 32767

3

-2147483648 to 2147483647

4

None of the mentioned

3

Multiple Choice

Modulus operator, %, can be applied to which of these?

1

Integers

2

Floating – point numbers

3

Both Integers and floating – point numbers

4

None of the mentioned

4

Multiple Choice

class evaluate {

public static void main(String args[]) {

int a[] = {1,2,3,4,5}; int d[] = a; int sum = 0;

for (int j = 0; j < 3; ++j)

sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);

System.out.println(sum); } }

1

38

2

39

3

41

4

40

5

Multiple Choice

Which of these can be returned by the operator &?

1

Integer

2

Boolean

3

Character

4

Integer or Boolean

6

Multiple Choice

class dynamic_initialization {

public static void main(String args[]) {

double a, b; a = 3.0; b = 4.0;

double c = Math.sqrt(a * a + b * b);

System.out.println(c); } }

1

5.0

2

25.0

3

7.0

4

Compilation Error

7

Multiple Choice

When Overloading does not occur?

1

More than one method with same name but different method signature and different number or type of parameters

2

More than one method with same name, same signature but different number of signature

3

More than one method with same name, same signature, same number of parameters but different type

4

More than one method with same name, same number of parameters and type but different signature

8

Multiple Choice

Which of these statements are incorrect?

1

Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms

2

Assignment operators run faster than their equivalent long forms

3

Assignment operators can be used only with numeric and character data type

4

None of the mentioned

9

Multiple Choice

class increment {

public static void main(String args[]) {

double var1 = 1 + 5;

double var2 = var1 / 4;

int var3 = 1 + 5;

int var4 = var3 / 4;

System.out.print(var2 + " " + var4); } }

1

1 1

2

0 1.5

3

1.5 1

4

1 1.5

10

Multiple Choice

class increment {

public static void main(String args[]) {

int g = 3;

System.out.print(++g * 8); } }

1

24

2

32

3

25

4

34

11

Multiple Choice

class Output {

public static void main(String args[]) {

int a = 1; int b = 2; int c; int d;

c = ++b;

d = a++;

c++;

b++;

++a;

System.out.println(a + " " + b + " " + c); } }

1

4 4 3

2

3 3 4

3

3 4 4

4

4 3 3

12

Multiple Choice

class bitwise_operator {

public static void main(String args[]) {

int var1 = 42;

int var2 = ~var1;

System.out.print(var1 + " " + var2); } }

1

42 42

2

42 -43

3

43 42

4

43 -42

13

Multiple Choice

class bitwise_operator {

public static void main(String args[]) {

int a = 3;

int b = 6;

int c = a | b;

int d = a & b;

System.out.println(c + " " + d); } }

1

7 2

2

7 5

3

5 7

4

7 7

14

Multiple Choice

class leftshift_operator {

public static void main(String args[]) {

byte x = 64; int i; byte y;

i = x << 2;

y = (byte) (x << 2)

System.out.print(i + " " + y); } }

1

0 256

2

256 0

3

0 64

4

256 1

15

Multiple Choice

class rightshift_operator {

public static void main(String args[]) {

int x; x = 10;

x = x >> 1;

System.out.println(x); } }

1

2

2

7

3

5

4

10

16

Multiple Choice

Which of these keywords can be used to prevent Method overriding?

1

static

2

constant

3

protected

4

final

17

Multiple Choice

At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among “final, static, native, public, private, abstract, protected”

public interface Status {

/* insert qualifier here */ int MY_VALUE = 10;

}

1

final, native, private

2

final, static, protected

3

final, private, abstract

4

final, static, public

18

Multiple Choice

What will be the output of the following Java program?

class Alligator {

public static void main(String[] args) {

int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

int [][]y = x;

System.out.println(y[2][1]); } }

1

2

2

3

3

7

4

Compilation Error

19

Multiple Choice

What will be the output of the following Java program?

class Abc {

public static void main(String[]args) {

String[] elements = { "for", "tea", "too" };

String first = (elements.length > 0) ? elements[0]: null; } }

1

Compilation error

2

An exception is thrown at run time

3

The variable first is set to null

4

The variable first is set to elements[0]

20

Multiple Choice

What will be the output of the following Java program?

class selection_statements {

public static void main(String args[]) {

int var1 = 5; int var2 = 6;

if ((var2 = 1) == var1)

System.out.print(var2);

else

System.out.print(++var2); } }

1

1

2

3

3

2

4

5

21

Multiple Choice

What will be the output of the following Java program?

class Output {

public static void main(String args[]) {

final int a=10,b=20;

while(a<b)

{

System.out.println("Hello"); }

System.out.println("World"); } }

1

Hello

2

run time error

3

Hello world

4

compile time error

22

Multiple Choice

What will be the output of the following Java program?

class Alligator {

public static void main(String[] args) {

int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

int [][]y = x;

System.out.println(y[2][1]); } }

1

2

2

3

3

7

4

Compilation Error

23

Multiple Choice

class increment {

public static void main(String args[]) {

double var1 = 1 + 5;

double var2 = var1 / 4;

int var3 = 1 + 5;

int var4 = var3 / 4;

System.out.print(var2 + " " + var4); } }

1

1 1

2

0 1.5

3

1.5 1

4

1 1.5

Java Programming

Slide image

Show answer

Auto Play

Slide 1 / 23

SLIDE