wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Revision Latih Tubi OOP

Total questions: 200

Worksheet time: 2hrs 58mins

Name
Class
Date
1.

What is UML?

a)

Unified Modelling Language

b)

Unification Multi Language

c)

Unified Multimedia Language

d)

Unity Modelling Language

2.

An Identifier with a Fix Value Stored.

a)

Data type

b)

Variable

c)

Constant

d)

Loop

3.

Syntax to create Object:

a)

Class Classname = NEW Classname();

b)

Classname objname = new Classname();

c)

Objectname Classname = New Objectname();

d)

Objectname Classname = new Classname();

4.

An instance of a class.

a)

Method

b)

Object

c)

Attribute

d)

Class

5.

A template used to define an object.  It specifies the methods and attributes an object should have.

a)

Class

b)

Method

c)

Attribute

d)

Polymorphism

6.

Ensuring private attributes can only be amended through public methods.  This prevents objects being manipulated in unintended ways.

a)

Polymorphism

b)

Inheritance

c)

Encapsulation

d)

Object Oriented Programming

(OOP)

7.

The ability for a class to inherit the methods and attributes of a parent class.  Its ‘child’ class can have its own methods and attributes and override methods of its parent class.

a)

Polymorphism

b)

Encapsulation

c)

Attribute

d)

Inheritance

8.

The ability for objects of different classes to be treated in the same way.  For example, the same method may be applied to objects of different classes.

a)

Object Oriented Programming

(OOP)

b)

Encapsulation

c)

Polymorphism

d)

Inheritance

9.

Advantage of Object oriented programming approach.

a)

Objects created can easily be reused in other programs

b)

Object oriented programs are much larger than other porgrams

c)

The probrams are slower than other programs

d)

Ability to run the same code on many different systems.

10.

Choose valid variable declaration.

a)

6Salary_Year

b)

Student name

c)

Student!

d)

stuName

11.

What is a class diagram?

a)

It shows user the system, scenario when user use the system.

b)

It shows data and the relationships between data.

c)

It describes types of objects in the system, show classes and relationship between them

d)

It shows the relationship of objects and object that participate in the message exchange.

12.

Default value for the element of an array of integer.

a)

0

b)

null

c)

'0'

d)

'\u0000'

13.

Write code out of this statement: "If value of the temperature is between 20.0 and 40.0, print " Very cold"

a)

if(!(temp<20.0 || temp >40.0)) {
System.out.print("Very Cold");
}

b)

if(20.0<= temp <=40.0)) {
System.out.print("Very Cold");
}

c)

if(temp >=20.0 || temp<=40.0){

System.out.print("very cold");

}

d)

if(temp >=20.0 | temp<=40.0){

System.out.print("very cold");

}

14.

Choose the correct error type for the code below:
if(X>Y);

System.out.println("X");

a)

Syntax Error

b)

Logic Error

c)

Run Time Error

d)

No Error

15.

Using JDK and command line, what command is used to compile a file in Java?

a)

java

b)

javac

c)

javacompile

d)

compile.java

16.

Select the type of statements that forces the next iteration of the loop to take place, skipping any code between itself and the conditional expression that controls the loop.

a)

continue

b)

return

c)

forward

d)

break

17.

What is the result of: x = 7; y = ++x * 3 - 2

a)

19

b)

20

c)

21

d)

22

18.

Which of the following options is considered to be a named memory location that can be assigned a value?

a)

method

b)

variable

c)

class

d)

object

19.

Select the appropriate variable name, by best practice.

a)

CM2019

b)

%_CM2019

c)

2019CM

d)

%CM2019

20.

What type of values represent the outcome of the relational and logical operators?

a)

constant values

b)

null values

c)

Boolean values

d)

absolute values

21.

Which of the following options is NOT a relational operator?

a)

==

b)

!=

c)

>=

d)

&&

22.

In Java programming, selection, iteration and jump are considered to be what type of statements?

a)

control statements

b)

structure statements

c)

transforming statements

d)

directive statements

23.

Which are the compatible Data Types for Type Promotion or Type Casting?

a)

A) byte, char, short

b)

B) char, int, float

c)

C) float, long, double

d)

D) All the above

24.

What is the output of the below Java code snippet?

char ch = 'A';//ASCII 65

int a = ch + 1;

ch = (char)a;

System.out.println(ch);

a)

A) 66

b)

B) A

c)

C) B

d)

D) 65

25.

What will be the Output of the below code:

public class Demo{

public static void main(String[] arr){

}

public static void main(String arr){

}

}

a)

a) Nothing

b)

b) Error

c)

C) Finite

d)

d) Hii

26.

What is the output of the following code snippet?

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

{ }

System.out.println(i);

a)

A. 5

b)

B. 0

c)

C. 4

d)

D. Compilation Error

27.

What is the output of the following Java Code?

int a=9;

float b = a/2;

System.out.println(b);

a)

A) 4.0

b)

B) 4.5

c)

C) 5.0

d)

D) None of the above

28.

Which example shows the correct syntax for a while loop?

a)
b)
c)
29.

In the following code, which line numbers are in scope for the favoriteNumber variable?

a)

3, 4

b)

1, 2

c)

1, 2, 3

d)

1, 2, 3, 4

30.

Which control flow statement is represented by a diamond shape in a flowchart diagram?

a)

while

b)

if

c)

do while

d)

None

31.

How would you best describe what control flow statements do in a program?

a)

They can cause a block of code to be executed after a program terminates abnormally.

b)

They can cause a block of code to be executed once, multiple times, or not at all.

c)

They can cause a block of code to be executed line by line in sequential order.

d)

They may cause Errors

32.

Given a symbol in each question, choose the best answer.

a)

Represents a decision-making point

b)

Represents arithmetic operations and data manipulations

c)

Represents the start and the end of a flowchart

d)

Represents the flow of the algorithm

e)

Input-Output

33.

How would you describe a while loop?

a)

Check the condition; if it is true, then run a code block. Otherwise, run a different code block.

b)

Check whether the condition is true; if it is true, then keep repeating until the condition is false.

c)

Run a block of code and then check the condition; if the condition is true, then repeat the block of code.

34.

Given a symbol in each question, choose the best answer.

a)

Represents a decision-making point

b)

Represents arithmetic operations and data manipulations

c)

Represents the start and the end of a flowchart

d)

Represents the flow of the algorithm

e)

Input-Output

35.

Given a symbol in each question, choose the best answer.

a)

Represents a decision-making point

b)

Represents arithmetic operations and data manipulations

c)

Represents the start and the end of a flowchart

d)

Represents the flow of the algorithm

e)

Input-Output

36.

Which component is used to compile,debug and execute the java programs ?

a)

JRE

b)

JIT

c)

JDK

d)

JVM

37.

Which one of the following is not a java feature

a)

Object-oriented

b)

Use of pointers

c)

Portable

d)

Dynamic and Extensible

38.

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

a)

Identifier & keyword

b)

Identifier

c)

Keyword

d)

None of the mentioned

39.

Which of these are selection statements in java

a)

Break

b)

Continue

c)

For ( )

d)

If ( )

40.

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

a)

Polymorphism

b)

Inheritance

c)

Compilation

d)

Encapsulation

41.

Which of the following is a superclass of every class in java ?

a)

ArrayList

b)

Abstract class

c)

Object class

d)

String

42.

Which of these keywords are used for the block to be examined for exceptions ?

a)

Check

b)

Throw

c)

Catch

d)

Try

43.

Which one of the following is not an access modifier ?

a)

Protected

b)

Void

c)

Public

d)

Private

44.

What is the numerical range of a char data tupe in java ?

a)

0 to 256

b)

-128 to 127

c)

0 to 65535

d)

0 to 32767

45.

When overloading does not occur ?

a)

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

b)

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

c)

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

d)

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

46.

What is it called if an object has its own life cycle and there is no owner

a)

Aggregation

b)

Composition

c)

Encapsulation

d)

Association

47.

Method overriding is combination of inheritance and polymorphism ?

a)

True

b)

False

48.

How can we identify whether a compilation unit is class or interface from a .class file ?

a)

Java source file header

b)

Extension of compilation unit

c)

We cannot different between class and interface

d)

The class or interface name should be postfixed with unit type

49.

What is use of interpreter ?

a)

They covert bytecode to machine language code

b)

They read high level code and execute them

c)

They are intermediated between JIT and JVM

d)

It is a synonym for JIT

50.

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

a)

Polymorphism

b)

Compilation

c)

Inheritance

d)

Encapsulation

51.

What is the value stored in x in following lines of code?

int x, y, z;

 x = 0;

 y = 1;

 x = y = z = 8;

a)

1

b)

9

c)

8

d)

0

52.

Evaluate the following Java expression, if x=3, y=5, and z=10:

++z + y - y + z + x++

a)

24

b)

23

c)

20

d)

25

53.

What is JVM ?

a)

JVM is the confined memory area

b)

All java programs run inside JVM memory

c)

JVM provides security to the computer by giving controlled access to Files and Memory on a computer

d)

All the above

54.

Composition uses the concept of ___________ relationship.

a)

has-a

b)

is-a

c)

one-to-one

d)

one-to-many

55.

Inheritance can use the concept of ___________ relationship.

a)

has-a

b)

is-a

c)

one-to-one

d)

one-to-many

56.

An abstract method is a method ____________

a)

with a return statement

b)

which cannot be overridden

c)

with a return statement and can be overridden

d)

with no definition

57.

In the JAVA programming language, the concept of keeping data private is known as __________.

a)

polymorphism

b)

information hiding

c)

static binding

d)

inheritance

58.

A(n) ________________is a blueprint that defines the variables and the methods common to all objects of a certain kind.

a)

Class

b)

Abstraction

c)

Encapsulation

d)

Inheritance

59.

Composition is also known as

a)

Modularity

b)

Encapsulation

c)

Aggregation

d)

Instantiation

60.

Choose the FALSE statement about abstract class

a)

It is a superclass with generic behaviour

b)

Definition of abstract method is implemented in subclass

c)

Subclasses must implement all the abstract methods in the superclass

d)

Abstract class must have more than one abstract method

61.

_______________ is a key concept, enabling an object of a subclass to be treated like an object of its superclass.

a)

Classes and subclasses

b)

Data abstraction

c)

Static polymorphism

d)

Information hiding

62.

Which of the following is true about method overloading?

a)

It allows a method to have different return types

b)

It is not possible in Java

c)

It involves creating multiple methods with the same name but different parameters

d)

It can only be done in abstract classes

63.
A collection of 8 bits is a _______, or a single allocation unit in RAM.
a)
Bite
b)
Byte
c)
Word
d)
Circuit
64.

What is the output of the following code snippet?

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

{ }

System.out.println(i);

a)

A. 5

b)

B. 0

c)

C. 4

d)

D. Compilation Error

65.

Function of the Scanner class to accept a float literal from the user is

a)

nextInt( )

b)

hasNext( )

c)

next( )

d)

nextFloat( )

66.

What is an exception

a)

Error occurred during the execution of a program

b)

Bug occurred during the compile time of a program

c)

Simply an Error

d)

It is related to input values

67.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

68.

class exception_handling

{ public static void main(String args[])

{ try

{ int a, b;

b = 0;

a = 5 / b;

System.out.print("A");

} catch(ArithmeticException e)

{ System.out.print("B");

}

finally

{ System.out.print("C");

}

}

}

a)

A

b)

B

c)

AC

d)

BC

69.
Is the following a valid method definition?
public static void welcomeBanner(char symbol)
{
     for (int i=0; i<60; i++)
          System.out.print(symbol);
     System.out.println(" ");
     
     System.out.println(symbol + "                  This is a Welcome Banner                    " + symbol);
     for (int i=0; i<60; i++)
          System.out.print(symbol);
     System.out.println(" ");
}
a)
Yes
b)
No
70.
Which of the following is a correct header line for main in a Java program?
a)
public static void main(args)
b)
public static void main(String args)
c)
public static void main(args [ ])
d)
public static void main(String [ ] args)
71.
What does a comment look like in Java?
a)
//comment
b)
\\comment
c)
==comment
d)
\comment
72.
A variable that holds a character
a)
String
b)
boolean
c)
int
d)
char
73.

What is the file extension for Java Source Code?

a)

.java

b)

.class

c)

.exe

d)

.obj

74.

What is the file extension for Java Executable Code?

a)

.java

b)

.class

c)

.exe

d)

.obj

75.

Java is case sensitive?

a)

True

b)

False

76.

public static void main (String [] args) is a:

a)

Program Container

b)

Main Method

c)

Statement Block

d)

Sentence

77.

Feature that allows programmers to create new classes that share some of the attributes of existing classes.

a)

Inheritance

b)

Polymorphism

c)

Encapsulation

d)

Abstraction

78.

Benefit of Object Oriented Design

a)

Reduce complexity through

b)

Automatic memory management

c)

Simplified Coding with Procedural Programming

d)

Improved security due to relational modelling

79.

Choose the right statement about behaviour in OOP

a)

Name and age attribute of "Person" Class

b)

A "Car" Object having colour and model as properties

c)

A "cat" Object responding to "meow()" method when called

d)

Class "Student" with no method or attributes

80.

Correct way to create StringBuffer object in java

a)

StringBuffer sb1 = new StringBuffer();

b)

StringBuffer sb1=0;

c)

StringBuffer sb1;

d)

StringBuffer sb1();

81.

Which method would you use to check if two Strings are exactly the same?

a)

equals()

b)

equalsIgnoreCase()

c)

toUpperCase()

d)

toLowerCase()

82.

Which method was used to convert this String: "IT learners are clever" to "IT LEARNERS ARE CLEVER" ?

a)

toUpperCase()

b)

toLowerCase()

c)

equalsIgnoreCase()

d)

compareTo()

83.

Which method was used to convert this String: "Life is TOO SHORT to be BORED" to: "life is too short to be bored" ?

a)

toLowerCase()

b)

toUpperCase()

c)

equals()

d)

equalsIgnoreCase()

84.

Is String a primitive data type?

a)

Yes

b)

No

c)

Both

85.

Which method to use to find length of a string?

a)

length()

b)

size()

c)

long()

d)

count()

86.

Which data type gets returned from length() method in String class?

a)

double

b)

String

c)

int

d)

number

87.

String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


What is the correct way to find the length of "txt" string?

a)

int len = length(txt);

b)

float len = txt.length();

c)

int len = txt.length();

d)

double len = length(txt);

88.

Choose correct purpose of indexOf() in String class.

a)

returns the index (the position) of the last occurrence of a specified text in a string

b)

returns the character of the first occurrence of a specified character in a string

c)

returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)

d)

returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)

89.

String x = "10";

String y = "20";

String z = x + y;

System.out.println(z);

Guess the output.

a)

1020

b)

10 20

c)

30

d)

"10 20"

90.

Which method would you use to see if two Strings contain the same letters but ignoring capitals and small letters?

a)

equals()

b)

equalsIgnoreCase()

c)

toUpperCase()

d)

compareTo()

91.

Which of the following are Java features?

a)

Object- oriented programming

b)

Class- based programming

c)

Bytecode is platform independent

d)

All of above

92.

char is 2 byte in storage?

a)

True

b)

False

93.

(=) sign means

a)

equals and it is used for math problems in Java

b)

assignment operator. It used to assign a value

94.
In the statement 
 Bank tom = new Bank(5000.0);
Which is the class?
a)
Bank
b)
tom
c)
new
d)
5000.0
95.
In the statement 
Bank tom = new Bank(5000.0);

Which is the object?
a)
Bank
b)
tom
c)
new
d)
5000.0
96.

Which method to use to find length of a string?

a)

length()

b)

size()

c)

long()

d)

count()

97.

What will be the output of below code?


String s1= "Hook'em Horns!";

println(s1.substring(1,2) + s1.substring(5));

a)

oem Horns!

b)

ooemHorns!

c)

Hem Horns!

d)

Error: Out of Bounds

98.

What will be the output of below code?


String s1= "Hook'em Horns!";

println("b" + s1.substring(1,3) + s1.substring(13,14));

a)

boo!

b)

book!

c)

boos!

d)

Error: Out of Bounds

99.

String s="my school";

int x = s.indexOf("c");

What is the value of x?

a)

1

b)

2

c)

4

d)

3

100.

String s1="whatever";

String s2 = s1.substring(1,4);

What is the value of s2?

a)

"hate"

b)

"hat"

c)

"whate"

d)

"what"

101.

Which method would you use to check if two Strings are exactly the same?

a)

equals()

b)

equalsIgnoreCase()

c)

toUpperCase()

d)

toLowerCase()

102.

is this code Good or Bad Java?

String greeting ="hi";

if (greeting == "hello")

{

}

a)

Good

b)

Bad

103.

String s ="Johannesburg"

System.out.print(s.substring(2,5) )

will return:

a)

ohan

b)

han

c)

hann

d)

oha

104.

What is the output of the following code?

String s1 = “Peter Pan”;

String s2 = “Humpty Dumpty”;

System.out.println(s1.compareTo(s2));

a)

0

b)

A positive integer

c)

A negative integer

d)

1

105.

What is the output of the following code?


String s1 = “Peter Pan”;

System.out.println(s1.indexOf(“eter”));

a)

1

b)

2

c)

3

d)

4

106.

What is the output of the following code?


String s1 = “Shakespeare”;

System.out.println(s1.replace(‘s’, ‘P’));

a)

PhakePpeare

b)

phxkeppexre

c)

Shakespeare

d)

All of them

107.

What code forms the basic skeleton of a while loop?

a)

while{….some code…. { …. Some code…}

b)

while { …. Some code…}

c)

while() ….some code…. { …. Some code…}

d)

while( ) { …some code}

108.

Java code to create a non-element array of student marks with the size of 20.

a)

double mark;

b)

double [20] mark = new double;

c)

double [ ] mark = new mark [20];

d)

double [ ] mark = new double [20];

109.

What is the correct relation between length and last-index of array?

a)

last-index is always 1 more than the length

b)

last-index is 1 less than the length (but not always)

c)

last-index is always 1 less than the length

d)

last-index is always equal to the length

110.

Java code to display the size of an array name studentname[ ].

a)

System.out.println("The size is " + studentname[ index ]);

b)

System.out.println("The size is " + studentname.length);

c)

System.out.println("The size is " + length.length);

d)

System.out.println("The size is " + studentname);

111.

Based on the code segment below:- identify the name of the array.


for(int j=0; j<balance.length; j++)

{

System.out.print("Enter amount: ");

.......

}

a)

No answer.

b)

temp[ ]

c)

balance

d)

balance [ i ]

112.

An abstract class can implement an interface.

a)

TRUE

b)

FALSE

113.

All methods in an interface are abstract by default.

a)

FALSE

b)

TRUE

114.

A class that extends an abstract class must implement all abstract methods of the superclass.

a)

TRUE

b)

FALSE

115.

An abstract class can have final methods.

a)

TRUE

b)

FALSE

116.

A class can extend multiple abstract classes in Java.

a)

TRUE

b)

FALSE

117.

Which keyword is used to declare an interface in Java?

a)

A. class

b)

B. abstract

c)

C. interface

d)

D. implements

118.

What is an interface in Java?

a)

A. A class with only abstract methods

b)

B. A reference type that contains only constants and abstract methods

c)

C. A class that cannot be extended

d)

D. A class with only concrete methods

119.

Can an abstract class have constructors?

a)

A. Yes

b)

B. No

c)

C. Only if it has abstract methods

d)

D. Only if it is final

120.

Can an interface extend another interface?

a)

A. Yes

b)

B. No

c)

C. Only if it is abstract

d)

D. Only if it is final

121.

What is the main purpose of an abstract class?

a)

A. To provide a base class that other classes can extend and share common functionality

b)

B. To create a class that cannot be extended

c)

C. To create a class with only static members

d)

D. To define multiple classes with the same name

122.

How do you declare an abstract method in Java?

a)

public abstract void methodName();

b)

public void methodName() = 0;

c)

public void abstract methodName();

d)

abstract public void methodName() {}

123.
If more than one class implements an interface, its methods are ____.
a)
aggregated
b)
public
c)
dependent
d)
polymorphic
124.
When the element type of an array is a(n) ____ or interface, objects of those types or any subtype can be directly inserted into the array.
a)
primitive
b)
concrete
c)
abstract
d)
reference
125.
When an object�s class is a subclass of a more general class.
a)
Extension
b)
Aggregation
c)
Inheritance
d)
Dependency
126.
Inheritance is used when the relationship between two classes is a(n) _______ relationship.
a)
"HAS-A"
b)
"PART-OF-A"
c)
"IS-A"
d)
inverse
127.
In the main method:
public static void main(String args[])
What does public accomplish?
a)
The method will be accessible by any Class
b)
The given method or variable is not instance related but Class related
c)
The method will not return any value
d)
Method name is searched by JVM as a starting point for an application
128.
What is abstraction in OOP Java?
a)
Hiding irrelevant data
b)
Displaying object details
c)
User implementation details
d)
Object functionality
129.
What is abstract in Java with example?
a)
Hiding functionality
b)
Object implementation
c)
Sending SMS
d)
Data hiding
130.
What is polymorphism?
a)
Ability to display a message
b)
Ability to display a message in different forms
c)
Ability to display different messages
d)
Ability to display a message in the same form
131.
Can you give a real-life example of polymorphism in Java?
a)
A car with different types of engines
b)
A person with different behaviors in different situations
c)
A building with different types of rooms
d)
A book with different chapters
132.
Why is polymorphism used in Java?
a)
Abstraction
b)
Reusability
c)
Encapsulation
d)
Inheritance
133.
What is polymorphism in OOP Java?
a)
Ability of an object to take on many forms
b)
A way to hide the implementation details of a class
c)
A type of inheritance
d)
A way to create new objects from an existing class
134.
The image shows an example of polymorphism in Java. Which of the following methods is called when the area() method is invoked on an object of the Shape class?
a)
Circle area()
b)
Triangle area()
c)
Rectangle area()
d)
Shape area()
135.
What is the data type of the gender variable in the Author class?
a)
String
b)
char
c)
int
d)
float
136.
Which type of polymorphism is the most common?
a)
Compile-time polymorphism
b)
Run-time polymorphism
c)
Ad hoc polymorphism
d)
Coercion polymorphism
137.
Which of the following statements is not true about overloading and overriding?
a)
Overloaded methods have the same name but different signatures.
b)
Overridden methods have the same name and the same signature.
c)
Overloaded methods are resolved at compile time.
d)
Overridden methods are resolved at run time.
138.
Which of the following methods is defined in the Dog class in the image?
a)
makeSound()
b)
makeSound(boolean injured)
c)
makeSound(int volume)
d)
makeSound(String sound)
139.
What is the concept of Java programming illustrated in the image?
a)
Method overloading
b)
Method overriding
c)
Abstract classes
d)
Interfaces
140.
What is the difference between a class and an object?
a)
A class is a blueprint to make an object
b)
An object is a blueprint to make a class
c)
A blueprint is an object to make a class
d)
Blueprint class is an object make a
141.
The wrapping up of data and functions into a single unit is called
a)
overloading
b)
class
c)
object
d)
encapsulation 
142.

You can make changes to an object with

a)

methods

b)

attributes

c)

modifiers

d)

parameters

143.

What keyword is used to create an object?

a)

new

b)

create

c)

build

d)

start

e)

main

144.

A method is...

a)

A way of calculating things in Java

b)

A strategy for programming

c)

A predefined set of instructions in a class

d)

A way to sore details in a class

145.

Which among the following best describes encapsulation?

a)

It is a way of combining various data members into a single unit

b)

It is a way of combining various member functions into a single unit

c)

It is a way of combining various data members and member functions into a single unit which can operate on any data

d)

It is a way of combining various data members and member functions that operate on those data members into a single unit

146.

Which inheritance in java programming is not supported

a)

Multiple inheritance

b)

hierarchal inheritance

c)

Multilevel inheritance

d)

Single inheritance

147.

What is subclass in java?

a)

A subclass is a class that extends another class

b)

A subclass is a class declared inside a class

c)

Both above.

d)

None of the above.

148.

If class B is subclassed from class A then which is the correct syntax

a)

class B:A{}

b)

class B extends A{}

c)

class B extends class A{}

d)

class B implements A{}

149.

Find which of the following uses encapsulation?

a)

void main(){

int a;

void fun() { int a=10;

System.out.println(a);

fun(); }

b)

class student{

int a;

public int b; };

c)

class student {

int a;

public void disp(){

System.out.println(a);

} }

d)

static topper() {

char name[10];

public int marks; }

150.

Which of this keyword must be used to inherit a class?

a)

super

b)

this

c)

extent

d)

extends

151.

Which among the following best defines abstraction?

a)

Hiding the implementation

b)

Showing the important data

c)

Hiding the important data

d)

Hiding the implementation and showing only the features

152.

If two classes combine some private data members and provides public member functions to access and manipulate those data members. Where is abstraction used?

a)

Using private access specifier for data members

b)

Using class concept with both data members and member functions

c)

Using public member functions to access and manipulate the data members

d)

Data is not sufficient to decide what is being used

153.

Which keyword is used to implement an interface in Java?

a)
uses
b)
implements
c)
inherits
d)
extends
154.

What will be the output of this code?

a)

Compilation error

b)

Method A

c)

Runtime error

d)

No output

155.

What is the default access modifier for methods declared in an interface?

a)

private

b)
protected
c)
package-private
d)

public

156.

What keyword is used to inherit from a class and to implement an interface in Java?

a)

inherit, derive

b)

extends, extends

c)

extends, implements

d)

implements, extends

157.

Which of the following correctly distinguishes a class from an interface in Java?

a)

Both classes and interfaces can have constructors

b)

Only interfaces can have constructors

c)

Only classes can have constructors

d)



Neither classes nor interfaces can have constructors

158.

Why can’t interfaces have constructors in Java?

a)
Interfaces can have constructors if they extend a class.
b)
Interfaces cannot have constructors because they cannot be instantiated.
c)
Constructors in interfaces are used for initialization.
d)
Interfaces can be instantiated like classes.
159.

Give an example of a real-world scenario where abstraction is used in Java.

a)

Designing a traffic light system for a city

b)

Developing a recipe management system for a restaurant

c)

Using a bank account class to represent a customer's account

d)

Creating a shopping cart for an online store

160.

Collection of similar classes, interfaces and sub packages

a)

variable

b)

Interface

c)

packages

d)

class

161.

API

a)

applet programming interface

b)

application programming interface

c)

all time program interterface

d)

None

162.

Uses of Packages

a)

easily maintained

b)

access protection

c)

avoid naming collision

d)

None

163.

what is the Syntax to define or create a package?

a)

     package <package_name>

b)

     package <package_name>;

c)

import      package <package_name>;

d)

none

164.

___________ is a collection of prewritten packages, classes, and interfaces with their respective methods, fields and constructors.

a)

API package

b)

class

c)

interface

d)

user defined package

165.

what is syntax to improt all the content of package?

a)

import packaage_name.class_name;

b)

import package_name.*;

c)

import pak1.pak2.pak3;

d)

None

166.

what is syntax to improt a particular class of package?

a)

import class_name.*;

b)

import package_name.*;

c)

import pak1.pak2.pak3;

d)

import packaage_name.class_name;

167.

which member of a class can be accessible by the another class of the same package?

a)

public

b)

private

c)

defualt

d)

protected

168.

which member of a class can be accessible by the class of another package?

a)

public

b)

private

c)

defualt

d)

protected

169.

which member of a class can be accessible by other member of the same class?

a)

public

b)

private

c)

defualt

d)

protected

170.

LIst top level access modifiers

a)

private

b)

package-private

c)

both

d)

none

171.

List member level access modifiers

a)

public

b)

private

c)

default

d)

protected

172.

What will be the output of the following program?

class A

{

 

}

 

class B extends A

{

 

}

 

class C extends B

{

 

}

 

public class MainClass

{

    static void overloadedMethod(A a)

    {

        System.out.println("ONE");

    }

 

    static void overloadedMethod(B b)

    {

        System.out.println("TWO");

    }

 

    static void overloadedMethod(Object obj)

    {

        System.out.println("THREE");

    }

 

    public static void main(String[] args)

    {

        C c = new C();

 

        overloadedMethod(c);

    }

}

a)

1

b)

2

c)

3

d)

4

173.

In a class, one method has two overloaded forms. One form is defined as static and another form is defined as non-static. Is that method properly overloaded?

a)

Yes

b)

No

174.

In the below Class X, is ‘method’ properly overloaded?

class X

{

    int method(int i, int d)

    {

        return i+d;

    }

 

    static int method(int i, double d)

    {

        return (int)(i+d);

    }

 

    double method(double i, int d)

    {

        return i+d;

    }

 

    static double method(double i, double d)

    {

        return i+d;

    }

}

a)

Yes

b)

No

175.

What will be the output of the following program?

class X

{

    void method(int a)

    {

        System.out.println("ONE");

    }

 

    void method(double d)

    {

        System.out.println("TWO");

    }

}

 

class Y extends X

{

    @Override

    void method(double d)

    {

        System.out.println("THREE");

    }

}

 

public class MainClass

{

    public static void main(String[] args)

    {

        new Y().method(100);

    }

}

a)

1

b)

2

c)

3

d)

4

176.

In a class, One method has 4 overloaded forms. All have different access modifiers (private, default, protected and public). Is that method properly overloaded?

a)

Yes

b)

No

177.

Method Overriding shows static polymorphism. True or false?

a)

True

b)

False

178.

What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?

a)

Method overloading

b)

Method overriding

c)

Method hiding

d)

None of the mentioned

179.

what is the output

a)

9.0 9.0

b)

9 9

c)

compile time error

d)

none

180.
a)

I am a Person

b)

I am a Student

c)

I am a Person I am a Student

d)

I am a Student I am a Person

181.

What do we call the creation of methods that all have the same name but different implementations?

a)

overloading

b)

inheritance

c)

polymorphism

d)

parameters

182.

What is the output of this program?

a)

1 2

b)

2 1

c)

Runtime Error

d)

Compilation Error

183.

Which import is needed for System.out

a)

java.lang.System

b)

no import is needed

c)

system.out

184.

The correct import for Scanner is the _______ import

a)

java.util.Scanner

b)

java.in.Scanner

c)

java.lang.Scanner

185.

Does Scanner throw an exception, and if so, which one?

a)

Yes, InputException

b)

Yes, IOException

c)

No, no exception is thrown

186.

Which is the correct way to declare an integer variable?

a)

int x = 3;

b)

integer x = 3;

c)

integer x is 3;

d)

int x is 3;

187.

Which is the correct numeric java type to use for decimals?

a)

Integer

b)

Double

c)

Char

d)

Boolean

e)

String

188.

Which variable declaration below is correct?

a)

int a = 4.5;

b)

char grade = 95;

c)

int a = 3/4;

d)

char grade = 'A';

189.

Which of these is not a valid input method?

a)

readInt

b)

readDouble

c)

readChar

d)

readBoolean

190.

Which of the following is a proper way to declare and initialize a variable in Java?

a)

myInteger = 100;

b)

char = 'a';

c)

int myNumber = 10;

d)

"Variable"

191.

Which of the below is not a primitive type in Java?

a)

int

b)

char

c)

boolean

d)

line

e)

double

192.

Which option correctly declares a string variable?

a)

String name = Chris;

b)

string name = "Chris";

c)

string name = 'Chris';

d)

String name = "Chris";

e)

String name = 'Chris';

193.

Which variable name is invalid?

a)

eightName

b)

_8name

c)

8name

d)

$eightname

194.

which one of the following is a legal decelration of a two- dimensional array of integers

a)

int[] a[] = new int[5][];

b)

int[5][5] a = new int[][];

c)

int a = new int[5,5];

d)

int[][] a = new int[][5];

195.

A class that is inherited is called a ______ .

a)

superclass

b)

Subclass

c)

subsetclass

d)

Relativeclass

196.

This is a general structure a method.

a)

<Returnvalue type> <Method Name> (argument / s)

b)

<Modifier> < type> <Method Name> (parameter / s)

c)

public static void main (String[ ] args)

d)

<Method Name> (parameter)

197.

Describe method.

a)

A component of a program in a big program.

b)

A program to perform a specific task.

c)

A component of a program written to perform a specific task.

d)

A variable that use to read an input.

198.

Which of the following is not a Java features?

a)

Dynamic

b)

Architecture Neutral

c)

Use of pointers

d)

Object-oriented

199.

Which of the following option leads to the portability and security of Java?

a)

Bytecode is executed by JVM

b)

The applet makes the Java code secure and portable

c)

Use of exception handling

d)

Dynamic binding between objects

200.

What does the expression float a = 35 / 0 return?

a)

0

b)

Not a Number

c)

Infinity

d)

Run time exception