wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

java Programming1

Total questions: 28

Worksheet time: 17mins

Name
Class
Date
1.

Java was developed by

a)

James gosling

b)

John gosling

c)

James frank

d)

John frank

2.

Which of the following is the correct main() method signature in Java?

a)

public static void main (String [] args)

b)

public static void Main (String [] args)

c)

public static void main (string [] args)

d)

public static void main (String args)

3.

Which of the following is a valid variable declaration in Java?

a)

int 1myInteger = 0;

b)

int int = 0;

c)

Int my Integer = 0;

d)

int myInteger = 0;

4.

Which of this command does not have errors?

a)

System.out.print("Hello World")

b)

System.out.print(Hello World);

c)

System.out.Print("Hello World);

d)

System.out.print("Hello World");

5.

What will be output of below program?

public class Test {

public static void main(String[] args) {

int x = 10*20-20;

System.out.println(x);

}

}

a)

Runtime Error

b)

Prints 180

c)

Prints 0

d)

None of the above

6.

What is the output for the following statement:

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

a)

11

b)

2

c)

Error Message

7.

Indicate the actual output of the statements below:

int thisYear = 2020;

System.out.println("The current year is "+thisYear);

a)

The current year is thisYear

b)

The current year is 2020

c)

No output; an error exists

d)

The current year is

8.

Which of the following is used as a terminator in Java programming?

a)

)

b)

;

c)

.

d)

>

9.

int x= 10;

int y = 20;

int z = x + y;

System.out.println(z);

Guess the output.

a)

1020

b)

10 20

c)

30

d)

"10 20"

10.

what is the output of this question?

class Test1 {

public

static void main(String[] args)

{

int x = 20;

System.out.println(x);

}

static

{

int x = 10;

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

}

}

a)

10 20

b)

20 10

c)

10 10

d)

20 20

11.

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

12.

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

13.

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

14.

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

15.

Which one of the following is a valid statement?

a)

char[] c = new char();

b)

char[] c = new char[5];

c)

char[] c = new char(4);

d)

char[] c = new char[];

16.

The following Syntax is used for?


class Subclass-name extends Superclass-name

{

//methods and fields

}

a)

Polymorphism

b)

Encapsulation

c)

Inheritance

d)

None of the above

17.
When the subclass method is intended as a replacement of the superclass method.
a)
Overriding
b)
Dependency
c)
Extension
d)
Aggregation
18.

Which of these is correct way of inheriting class A by class B?

a)

class B + class A {}

b)

class B inherits class A {}

c)

class B extends A {}

d)

class B extends class A {}

19.

Output of following Java program?

a)

Base

Derived

Derived

b)

Base

Base

Derived

c)

Base

Derived

Base

d)

Compiler Error

20.

When saving a Java source file, save it with an extension of

a)

.java.

b)

.javac.

c)

.src.

d)

.class.

21.

Which of the following is not a rule that must be followed when naming identifiers?

a)

After the first character, you may use the letters a-z, A-Z, an underscore, a dollar sign, or digits 0-9.

b)

Identifiers can contain spaces.

c)

Uppercase and lowercase characters are distinct.

d)

The first character must be one of the letters a-z, A-Z, an underscore or a dollar sign.

22.

To print "Hello, world" on the monitor, use the following Java statement:

a)

System.out.println("Hello, world");

b)

System Print = "Hello, world";

c)

SystemOutPrintln('Hello, world');

d)

system.out.println{Hello, world};

23.

Which of these statement is incorrect?

a)

Every class must contain a main() method

b)

Applets do not require a main() method at all

c)

There can be only one main() method in a program

d)

main() method must be made public

24.

What is the extension of compiled java classes?

a)

.java

b)

.class

c)

.txt

d)

.js

25.

Where does a java program start executing instructions from:

a)

class

b)

source file

c)

main method

d)

object

26.

Which of these keywords is used to make a class?

a)

class

b)

struct

c)

int

d)

none of the mentioned

27.

Which of the following is a type of polymorphism in Java?

a)

Compile time polymorphism

b)

Execution time polymorphism

c)

Multiple polymorphism

d)

Multilevel polymorphism

28.

Which of the following is not OOPS concept in Java?

a)

Inheritance

b)

Encapsulation

c)

Polymorphism

d)

Compilation