wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Tokens Identifiers Keyword

Total questions: 69

Worksheet time: 38mins

Name
Class
Date
1.

Which of these cannot be used for a variable name in java ?

a)

Identifier & keyword

b)

Identifier

c)

Keyword

d)

None of the mentioned

2.

Which of these are selection statements in java

a)

Break

b)

Continue

c)

For ( )

d)

If ( )

3.

Which statement is true about Java?

a)

Java is a sequence-dependent programming language

b)

Java is a code dependent programming language

c)

Java is a platform-dependent programming language

d)

Java is a platform-independent programming language

4.

Which of these cannot be used for a variable name in Java?

a)

identifier & keyword

b)

identifier

c)

keyword

d)

none of the mentioned

5.

What is the value of g?

int g = 3;

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

(a)  

6.

Which of the following is not an OOPS concept in Java?

a)

Polymorphism

b)

Inheritance

c)

Compilation

d)

Encapsulation

7.

StringBuffer s1 = new StringBuffer("Quiz");

StringBuffer s2 = s1.reverse();

System.out.println(s2);

Find the Output?

a)

QuizziuQ

b)

Quiz

c)

ziuQQuiz

d)

ziuQ

8.

Select the valid statement.

a)

char[] ch = new char(5);

b)

char[] ch = new char[5];

c)

char[] ch = new char();

d)

char[] ch = new char[];

9.

When is the object created with new keyword?

a)

At run time

b)

At compile time

c)

Depends on the code

d)

None

10.

Identify the corrected definition of a package.

a)

A package is a collection of editing tools

b)

A package is a collection of classes

c)

A package is a collection of classes and interfaces

d)

A package is a collection of interfaces

11.

Identify the keyword among the following that makes a variable belong to a class,rather than being defined for each instance of the class.

a)

final

b)

static

c)

volatile

d)

abstract

12.

Identify the output of the following program.

String str = “abcde”; System.out.println(str.substring(1, 3));

a)

abc

b)

bc

c)

bcd

d)

cd

13.

Identify the return type of a method that does not return any value.

a)

int

b)

void

c)

double

d)

None

14.

Exception created by try block is caught in which block

a)

catch

b)

throw

c)

final

d)

none

15.

Which of the following exception is thrown when divided by zero statement is executed?

a)

NullPointerException

b)

NumberFormatException

c)

ArithmeticException

d)

None

16.

What is not type of inheritance?

a)

Single inheritance

b)

Double inheritance

c)

Multiple inheritance

d)

Hierarchical inheritance

17.

Which of these keywords is used to refer to member of base class from a sub class?

a)

super

b)

native

c)

this

d)

None

18.

Which statements are true?

a)

Overriding can be achieved with static methods

b)

Final marked methods can be overridden

c)

Overloading is runtime.

d)

Return type can change in case of Overloading.

19.

Choose a correct statement about Java Interfaces?

a)

Interface contains only abstract methods by default.

b)

A Java class can implement multiple interfaces

c)

An Interface can extend or inherit another Interface.

d)

All the above

20.

A Java Class inherits Constants and Methods of an Interface using ____ keyword.

a)

implements

b)

extends

c)

import

d)

none

21.

What is the use of final keyword in Java?

a)

When a class is made final, a sublcass of it can not be created.

b)

When a method is final, it can not be overridden.

c)

When a variable is final, it can be assigned value only once.

d)

All of the above

22.

Which of these keywords is used to manually throw an exception?

a)

throws

b)

thow

c)

try

d)

finally

23.

Guess The Output

----------------------------

int $abc=10;

System.out.println($abc);

a)

10

b)

11

c)

Error

d)

13

24.

How many Keywords in JAVA ?

a)

32

b)

42

c)

40

d)

50

25.

Why Java is not 100% Object-oriented? Choose the Reasons Below !

a)

Primitive Data Types

b)

By Static Keyword

c)

Data Processing

d)

Annotations

26.

When programming, you have to use Data Types. Which of the following refers to interfaces, classes, and arrays?

a)

Primitive

b)

Non-Primitive

c)

Arrays

d)

Boolean

27.

Classes and interfaces use a certain type of data type. Which one is it?

a)

Primitive

b)

Non-primitive

c)

Floating Point

d)

None of the answers

28.

What is the main difference between float and double data types?

a)

4.1 is an example of float.

b)

4.11 is an example of double.

c)

Float consists of 8 bytes, and double consists of 4 bytes.

d)

Float consists of 4 bytes, and double consists of 8 bytes.

29.

What kind of data type is used for numbers?

a)

Integer

b)

String

c)

Boolean

d)

Floating Point

30.

Java Tokens help the compiler. Which of the following is a type of Java Token?

a)

Identifiers

b)

Keywords

c)

Operators

d)

All of the answers.

31.

What is a blueprint and determines how an object will behave?

a)

Object

b)

Method

c)

Attribute

d)

Class

32.
a)

0

b)

Garbage value

c)

Compilation error

d)

Runtime error

33.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

34.

which of the these variables allowed in java.

a)

Local Variables

b)

Instance Variables

c)

Static Variables

d)

All the above

e)

none of the above

35.
a)

sum is 1020

b)

sum is 30

c)

airthmetic error

36.
a)

40

b)

30

c)

20

d)

10

37.

a)

-10

b)

10

c)

error

38.

predict output

a)

Could not find or load main class sample

b)

Could not find or load main class Hai

c)

printed Hai

d)

file name class name must me same

39.

At the end of this fragment of code what is r1.count value?

a)

10

b)

-5

c)

6

d)

7

e)

8

40.

predict output

a)

10

b)

5

c)

error

41.

predict the output

a)

10

b)

25

c)

10 25

d)

25 10

42.

a)

1,2

b)

2,3

c)

1,2,3

d)

1,2,3,4

43.

What is instance variable?

a)

Instance variables are static variables within a class but outside any method

b)

Instance variables are variables defined inside methods, constructors or blocks

c)

Instance variables are variables within a class but outside any method

d)

None of the mentioned

44.

Which of these operators is used to allocate memory for an object?

a)

malloc

b)

alloc

c)

new

d)

assign

45.

Is static is a keyword.

a)

True

b)

False

46.

Scope of the local variable?

a)

within function

b)

outside function

c)

within class

d)

outside class

47.

class A

{

byte a;

int b;

long c;

public static void main(String args[])

{

A obj=new A();

}

}

What is the size of the object obj in bytes?

a)

11

b)

12

c)

13

d)

14

48.

static variables can be accessed without objects.

a)

True

b)

False

49.

public class Test1

{

//non-instance variable or data member

static int a;

//member fn

public static void main (String args[])

{

//local variable

int b=20;

Test1 ob=new Test1();

a=10;

System.out.println((a+b));

ob.display();

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

}

//member fn

void display()

{

int c=30;

Test1 obj=new Test1();

a=20;

}

}

a)

30

30

b)

30

50

c)

30

40

d)

30

20

50.

class A

{

int a;

String b;

float c;

}

The above class contains (a)   many instance variables

51.

Predict the output of the following program.


class A{

int a=40;//non static

public static void main(String args[]){

System.out.println(a);

}

}

a)

Compilation Error

b)

40

c)

0

d)

None of the above

52.

what is the output of this question?

class Test1 {

static int x = 10;

public

static void main(String[] args)

{

Test1 t1 = new Test1();

Test1 t2 = new Test1();

t1.x = 20;

System.out.print(t1.x + " ");

System.out.println(t2.x);

}

}

a)

10 10

b)

20 20

c)

10 20

d)

20 10

53.

What is the output of this question?

class Test1 {

static int i = 1;

public static void main(String[] args)

{

for (int i = 1; i < 10; i++) {

i = i + 2;

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

}

}

}

a)

3 6 9

b)

3 6 9 …. 27

c)

Error

d)

none

54.

What is the output of this question?

class Test1 {

static int i = 1;

public static void main(String[] args)

{

int i = 1;

for (Test1.i = 1; Test1.i < 10; Test1.i++) {

i = i + 2;

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

}

}

}

a)

1 3 9

b)

1 2 3 … 9

c)

3 5 7 9 11 13 15 17 19

d)

None

55.

Which of the following variable is declared as static?

a)

Home address of a particular Student

b)

Account number of a Customer

c)

Company name of all Employees in an Organization

d)

Name of a Employee

56.

Static variables belongs to an Object?

a)

Yes

b)

No

57.

What is the output of the following code?

public class Demo

{

static int x=10;

int y =15;

public Demo()

{

x++;

y++;

}


public static void main(String[] args)

{

Demo d1= new Demo();

Demo d2= new Demo();

Demo d3= new Demo();

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

}


}

a)

13,15

b)

13,16

c)

13,18

d)

10, 18

58.

How would you declare a variable storing the tax rate?

a)

int taxRate = 5.1;

b)

taxRate = "5.1";

c)

double taxRate = 5.1;

d)

double taxRate = "5.1";

e)

I do hereby declare thee Sir Tax Rate

59.

How would you declare a variable storing a person's name?

a)

string name = "Elroy";

b)

name String = "Elroy";

c)

String name = Elroy;

d)

String name = "Elroy";

e)

Me llamo Elroy

60.

How would you declare a variable that tells you that someone passed a class?

a)

boolean passed = 'true';

b)

boolean passed = true;

c)

passed = true;

d)

String passed = "true";

e)

Trick question - no one passes this class

61.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

62.

What prints out "I love Java" successfully?

a)

System.out.println(I love Java);

b)

Systemoutprintln("I love Java);

c)

System.out.println("I love" + " Java");

d)

System.out.println("I love Java")

e)

What is love? Baby dont hurt me. Dont hurt me. No more.

63.

Which function is used to input int value in Java using Scanner class?

a)

scanner_object . nextInteger( )

b)

scanner_object . nextInt( )

c)

scanner_object . nextint( )

d)

scanner_object . NextInt( )

64.

Which function is used to input float value in Java using Scanner class?

a)

scanner_object . nextFloat( )

b)

scanner_object . nextInt( )

c)

scanner_object . nextfloat( )

d)

scanner_object . NextFloat( )

65.

What data type would you use for storing the average test score in a class?

a)

double

b)

String

c)

int

d)

char

66.

Which company owns Java?

a)

Oracle

b)

Microsoft

c)

Google

d)

Apple

e)

Intel

67.

The average salary of a Java developer in the USA?

a)

$23,975

b)

$43,975

c)

$63,975

d)

$83,975

68.

Is Android based on Java?

a)

True

b)

False

69.

What was Java originally designed for?

a)

Interactive TV

b)

Internet

c)

Gaming

d)

Cars