Programmin

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

1

Find the output of the following program.

public class Solution{

public static void main(String[] args){

byte x = 127;

x++;

x++;

System.out.print(x);

1) -127

2) 129

3)2

ans : -127

2..

Find the output of the following program.

public class Solution{

public static void main(String[] args){

int[] x = {120, 200, 016};

for(int i = 0; i < x.length; i++){

System.out.print(x[i] + “ “);

1. 120 200 016

2. 120 200 14

3 .none

ans : 120 200 14


3

Find the value of A[1] after execution of the following program.

int[] A = {0,2,4,1,3};

for(int i = 0; i < a.length; i++){

a[i] = a[(a[i] + 3) % a.length];

a.0

b.1

c.3

ans :1

4.

Identify the output of the following program.

Public class Test{

Public static void main(String argos[]){

String str1 = “one”;

String str2 = “two”;

System.out.println(str1.concat(str2));

a.one

b.two

c . one two

ans :one two

5.

Find the output of the following code.


int ++a = 100;

System.out.println(++a);

a.101

b.Compile error as ++a is not valid identifier

c . 100

ans :Compile error as ++a is not valid identifier

6.

Find the output of the following code.

if(1 + 1 + 1 + 1 + 1 == 5){

System.out.print(“TRUE”);

else{

System.out.print(“FALSE”);

a.true

2 .false

3.compile error

ans: true

Find the output of the following code.

Public class Solution{

Public static void main(String args[]){


Int i;

for(i = 1; i < 6; i++){

if(i > 3) continue;

System.out.println(i);

a. 3

b.4

c. 5

d. 6

ans:6

8.How many times will “Interviewbit” be printed.

Int count = 0;

do{

System.out.println(“Interviewbit”);

count++;

} while(count < 10);

a. 8

b .9

c. 10

ans: 10

9.What will be the output of the following Java code?

class increment {

public static void main(String args[])


{

int g = 3;

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

a) 32

b) 33

c) 24

d) 25

ans 32

10.What will be the output of the following Java program?

class Output

public static void main(String args[])

int arr[] = {1, 2, 3, 4, 5};

for ( int i = 0; i < arr.length - 2; ++i)

System.out.println(arr[i] + " ");

a) 1 2 3 4 5

b) 1 2 3 4

c) 1 2

d) 1 2 3

ans:1 2 3
11.class abc

public static void main(String args[])

if(args.length>0)

System.out.println(args.length);

a) The snippet compiles and runs but does not print anything

b) The snippet compiles, runs and prints 0

c) The snippet compiles, runs and prints 1

d) The snippet does not compile

ans:The snippet compiles and runs but does not print anything

12.24. What will be the output of the following Java program?

class recursion

int func (int n)

int result;

if (n == 1)

return 1;

result = func (n - 1);

return result;
}

class Output

public static void main(String args[])

recursion obj = new recursion() ;

System.out.print(obj.func(5));

a) 1

b) 120

c) 0

d) None of the mentioned

Answer 1

13

class output

public static void main(String args[])

String c = "Hello i love java";

boolean var;

var = c.startsWith("hello");

System.out.println(var);

}
a) 0

b) true

c) 1

d) false

ans: false

14.What will be the output of the following Java program?

class Output

public static void main(String args[])

double x = 2.0;

double y = 3.0;

double z = Math.pow( x, y );

System.out.print(z);

a) 9.0

b) 8.0

c) 4.0

d) 2.0

ans 8.0

15. class overload

int x;
double y;

void add(int a , int b)

x = a + b;

void add(double c , double d)

y = c + d;

overload()

this.x = 0;

this.y = 0;

class Overload_methods

public static void main(String args[])

overload obj = new overload();

int a = 2;

double b = 3.2;

obj.add(a, a);

obj.add(b, b);

System.out.println(obj.x + " " + obj.y);

a) 4 6.4

b) 6.4 6

c) 6.4 6.4
ans : 4 6.4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy