wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Basics

Total questions: 12

Worksheet time: 5mins

Name
Class
Date
1.

Java Source Code is compiled into

a)

.Obj

b)

Source Code

c)

Bytecode

d)

.Exe

2.

Single line comment starts with _________ in Java.

a)

/**

b)

//

c)

/*

d)

None of these

3.

Java is case sensitive?

a)

True

b)

False

c)

Depends On Complier

d)

May be true or false

4.

How to compile java code in command prompt?

a)

javac filename.java

b)

java filename.java

c)

javac filename

d)

java filename

5.

What is true in Java?

a)

For all class names the first letter should be in Upper Case.

b)

All method names should start with a Lower Case letter.

c)

Name of the program file should exactly match the class name.

d)

All of the above

6.

All Java components require names. Names used for classes, variables, and methods are called?

a)

Variables

b)

identifiers

c)

Access Modifiers

d)

Java Modifiers

7.

What is JRE?

a)

JRE is a java based GUI application.

b)

JRE is an implementation of the Java Virtual Machine which executes Java programs.

c)

JRE is an application development framework.

d)

None of the above

8.

Default, public , protected, private are?

a)

Access Modifier

b)

Non-access Modifiers

c)

Both A and B

d)

It's variable

9.

What will be the output of the program?class PassA

{

public static void main(String [] args)

{

PassA p = new PassA();

p.start();

}


void start()

{

long [] a1 = {3,4,5};

long [] a2 = fix(a1);

System.out.print(a1[0] + a1[1] + a1[2] + " ");

System.out.println(a2[0] + a2[1] + a2[2]);

}


long [] fix(long [] a3)

{

a3[1] = 7;

return a3;

}

}

a)

12 15

b)

15 15

c)

3 4 5 3 7 5

d)

3 7 5 3 7 5

10.

What will be the output of the program?

class PassS

{

public static void main(String [] args)

{

PassS p = new PassS();

p.start();

}


void start()

{

String s1 = "slip";

String s2 = fix(s1);

System.out.println(s1 + " " + s2);

}


String fix(String s1)

{

s1 = s1 + "stream";

System.out.print(s1 + " ");

return "stream";

}

}

a)

slip stream

b)

slipstream stream

c)

stream slip stream

d)

slipstream slip stream

11.

What will be the output of the program?class Equals

{

public static void main(String [] args)

{

int x = 100;

double y = 100.1;

boolean b = (x = y); /* Line 7 */

System.out.println(b);

}

}

a)

true

b)

false

c)

Compilation fails

d)

An exception is thrown at runtime

12.

What will be the output of the program?

class Test

{

public static void main(String [] args)

{

int x= 0;

int y= 0;

for (int z = 0; z < 5; z++)

{

if (( ++x > 2 ) && (++y > 2))

{

x++;

}

}

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

}

}

a)

5 2

b)

5 3

c)

6 3

d)

6 4