Font size
WorksheetsRevision Latih Tubi OOP
Total questions: 200
Worksheet time: 2hrs 58mins
What is UML?
Unified Modelling Language
Unification Multi Language
Unified Multimedia Language
Unity Modelling Language
An Identifier with a Fix Value Stored.
Data type
Variable
Constant
Loop
Syntax to create Object:
Class Classname = NEW Classname();
Classname objname = new Classname();
Objectname Classname = New Objectname();
Objectname Classname = new Classname();
An instance of a class.
Method
Object
Attribute
Class
A template used to define an object. It specifies the methods and attributes an object should have.
Class
Method
Attribute
Polymorphism
Ensuring private attributes can only be amended through public methods. This prevents objects being manipulated in unintended ways.
Polymorphism
Inheritance
Encapsulation
Object Oriented Programming
(OOP)
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.
Polymorphism
Encapsulation
Attribute
Inheritance
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.
Object Oriented Programming
(OOP)
Encapsulation
Polymorphism
Inheritance
Advantage of Object oriented programming approach.
Objects created can easily be reused in other programs
Object oriented programs are much larger than other porgrams
The probrams are slower than other programs
Ability to run the same code on many different systems.
Choose valid variable declaration.
6Salary_Year
Student name
Student!
stuName
What is a class diagram?
It shows user the system, scenario when user use the system.
It shows data and the relationships between data.
It describes types of objects in the system, show classes and relationship between them
It shows the relationship of objects and object that participate in the message exchange.
Default value for the element of an array of integer.
0
null
'0'
'\u0000'
Write code out of this statement: "If value of the temperature is between 20.0 and 40.0, print " Very cold"
if(!(temp<20.0 || temp >40.0)) {
System.out.print("Very Cold");
}
if(20.0<= temp <=40.0)) {
System.out.print("Very Cold");
}
if(temp >=20.0 || temp<=40.0){
System.out.print("very cold");
}
if(temp >=20.0 | temp<=40.0){
System.out.print("very cold");
}
Choose the correct error type for the code below:
if(X>Y);
System.out.println("X");
Syntax Error
Logic Error
Run Time Error
No Error
Using JDK and command line, what command is used to compile a file in Java?
java
javac
javacompile
compile.java
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.
continue
return
forward
break
What is the result of: x = 7; y = ++x * 3 - 2
19
20
21
22
Which of the following options is considered to be a named memory location that can be assigned a value?
method
variable
class
object
Select the appropriate variable name, by best practice.
CM2019
%_CM2019
2019CM
%CM2019
What type of values represent the outcome of the relational and logical operators?
constant values
null values
Boolean values
absolute values
Which of the following options is NOT a relational operator?
==
!=
>=
&&
In Java programming, selection, iteration and jump are considered to be what type of statements?
control statements
structure statements
transforming statements
directive statements
Which are the compatible Data Types for Type Promotion or Type Casting?
A) byte, char, short
B) char, int, float
C) float, long, double
D) All the above
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) 66
B) A
C) B
D) 65
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) Nothing
b) Error
C) Finite
d) Hii
What is the output of the following code snippet?
int i = 0; for(i = 0 ; i < 5; i++)
{ }
System.out.println(i);
A. 5
B. 0
C. 4
D. Compilation Error
What is the output of the following Java Code?
int a=9;
float b = a/2;
System.out.println(b);
A) 4.0
B) 4.5
C) 5.0
D) None of the above
Which example shows the correct syntax for a while loop?
In the following code, which line numbers are in scope for the favoriteNumber variable?
3, 4
1, 2
1, 2, 3
1, 2, 3, 4
Which control flow statement is represented by a diamond shape in a flowchart diagram?
while
if
do while
None
How would you best describe what control flow statements do in a program?
They can cause a block of code to be executed after a program terminates abnormally.
They can cause a block of code to be executed once, multiple times, or not at all.
They can cause a block of code to be executed line by line in sequential order.
They may cause Errors
Given a symbol in each question, choose the best answer.
Represents a decision-making point
Represents arithmetic operations and data manipulations
Represents the start and the end of a flowchart
Represents the flow of the algorithm
Input-Output
How would you describe a while loop?
Check the condition; if it is true, then run a code block. Otherwise, run a different code block.
Check whether the condition is true; if it is true, then keep repeating until the condition is false.
Run a block of code and then check the condition; if the condition is true, then repeat the block of code.
Given a symbol in each question, choose the best answer.
Represents a decision-making point
Represents arithmetic operations and data manipulations
Represents the start and the end of a flowchart
Represents the flow of the algorithm
Input-Output
Given a symbol in each question, choose the best answer.
Represents a decision-making point
Represents arithmetic operations and data manipulations
Represents the start and the end of a flowchart
Represents the flow of the algorithm
Input-Output
Which component is used to compile,debug and execute the java programs ?
JRE
JIT
JDK
JVM
Which one of the following is not a java feature
Object-oriented
Use of pointers
Portable
Dynamic and Extensible
Which of these cannot be used for a variable name in java ?
Identifier & keyword
Identifier
Keyword
None of the mentioned
Which of these are selection statements in java
Break
Continue
For ( )
If ( )
Which of the following is not an OOPS concept in java ?
Polymorphism
Inheritance
Compilation
Encapsulation
Which of the following is a superclass of every class in java ?
ArrayList
Abstract class
Object class
String
Which of these keywords are used for the block to be examined for exceptions ?
Check
Throw
Catch
Try
Which one of the following is not an access modifier ?
Protected
Void
Public
Private
What is the numerical range of a char data tupe in java ?
0 to 256
-128 to 127
0 to 65535
0 to 32767
When overloading does not occur ?
More than one method with same name but different method signature and different number or type of parameters
More than one method with same name,same signature but different number of signature
More than one method with same name,same signature,same number of parameters but different type
More than one method with same , same number of parameters and type but different signature
What is it called if an object has its own life cycle and there is no owner
Aggregation
Composition
Encapsulation
Association
Method overriding is combination of inheritance and polymorphism ?
True
False
How can we identify whether a compilation unit is class or interface from a .class file ?
Java source file header
Extension of compilation unit
We cannot different between class and interface
The class or interface name should be postfixed with unit type
What is use of interpreter ?
They covert bytecode to machine language code
They read high level code and execute them
They are intermediated between JIT and JVM
It is a synonym for JIT
Which of the following is not an OOPS concept in Java?
Polymorphism
Compilation
Inheritance
Encapsulation
What is the value stored in x in following lines of code?
int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
1
9
8
0
Evaluate the following Java expression, if x=3, y=5, and z=10:
++z + y - y + z + x++
24
23
20
25
What is JVM ?
JVM is the confined memory area
All java programs run inside JVM memory
JVM provides security to the computer by giving controlled access to Files and Memory on a computer
All the above
Composition uses the concept of ___________ relationship.
has-a
is-a
one-to-one
one-to-many
Inheritance can use the concept of ___________ relationship.
has-a
is-a
one-to-one
one-to-many
An abstract method is a method ____________
with a return statement
which cannot be overridden
with a return statement and can be overridden
with no definition
In the JAVA programming language, the concept of keeping data private is known as __________.
polymorphism
information hiding
static binding
inheritance
A(n) ________________is a blueprint that defines the variables and the methods common to all objects of a certain kind.
Class
Abstraction
Encapsulation
Inheritance
Composition is also known as
Modularity
Encapsulation
Aggregation
Instantiation
Choose the FALSE statement about abstract class
It is a superclass with generic behaviour
Definition of abstract method is implemented in subclass
Subclasses must implement all the abstract methods in the superclass
Abstract class must have more than one abstract method
_______________ is a key concept, enabling an object of a subclass to be treated like an object of its superclass.
Classes and subclasses
Data abstraction
Static polymorphism
Information hiding
Which of the following is true about method overloading?
It allows a method to have different return types
It is not possible in Java
It involves creating multiple methods with the same name but different parameters
It can only be done in abstract classes
What is the output of the following code snippet?
int i = 0; for(i = 0 ; i < 5; i++)
{ }
System.out.println(i);
A. 5
B. 0
C. 4
D. Compilation Error
Function of the Scanner class to accept a float literal from the user is
nextInt( )
hasNext( )
next( )
nextFloat( )
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
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
B
AC
BC
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(" ");
}
What is the file extension for Java Source Code?
.java
.class
.exe
.obj
What is the file extension for Java Executable Code?
.java
.class
.exe
.obj
Java is case sensitive?
True
False
public static void main (String [] args) is a:
Program Container
Main Method
Statement Block
Sentence
Feature that allows programmers to create new classes that share some of the attributes of existing classes.
Inheritance
Polymorphism
Encapsulation
Abstraction
Benefit of Object Oriented Design
Reduce complexity through
Automatic memory management
Simplified Coding with Procedural Programming
Improved security due to relational modelling
Choose the right statement about behaviour in OOP
Name and age attribute of "Person" Class
A "Car" Object having colour and model as properties
A "cat" Object responding to "meow()" method when called
Class "Student" with no method or attributes
Correct way to create StringBuffer object in java
StringBuffer sb1 = new StringBuffer();
StringBuffer sb1=0;
StringBuffer sb1;
StringBuffer sb1();
Which method would you use to check if two Strings are exactly the same?
equals()
equalsIgnoreCase()
toUpperCase()
toLowerCase()
Which method was used to convert this String: "IT learners are clever" to "IT LEARNERS ARE CLEVER" ?
toUpperCase()
toLowerCase()
equalsIgnoreCase()
compareTo()
Which method was used to convert this String: "Life is TOO SHORT to be BORED" to: "life is too short to be bored" ?
toLowerCase()
toUpperCase()
equals()
equalsIgnoreCase()
Is String a primitive data type?
Yes
No
Both
Which method to use to find length of a string?
length()
size()
long()
count()
Which data type gets returned from length() method in String class?
double
String
int
number
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
What is the correct way to find the length of "txt" string?
int len = length(txt);
float len = txt.length();
int len = txt.length();
double len = length(txt);
Choose correct purpose of indexOf() in String class.
returns the index (the position) of the last occurrence of a specified text in a string
returns the character of the first occurrence of a specified character in a string
returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)
returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)
String x = "10";
String y = "20";
String z = x + y;
System.out.println(z);
Guess the output.
1020
10 20
30
"10 20"
Which method would you use to see if two Strings contain the same letters but ignoring capitals and small letters?
equals()
equalsIgnoreCase()
toUpperCase()
compareTo()
Which of the following are Java features?
Object- oriented programming
Class- based programming
Bytecode is platform independent
All of above
char is 2 byte in storage?
True
False
(=) sign means
equals and it is used for math problems in Java
assignment operator. It used to assign a value
Bank tom = new Bank(5000.0);
Which is the class?
Bank tom = new Bank(5000.0);
Which is the object?
Which method to use to find length of a string?
length()
size()
long()
count()
What will be the output of below code?
String s1= "Hook'em Horns!";
println(s1.substring(1,2) + s1.substring(5));
oem Horns!
ooemHorns!
Hem Horns!
Error: Out of Bounds
What will be the output of below code?
String s1= "Hook'em Horns!";
println("b" + s1.substring(1,3) + s1.substring(13,14));
boo!
book!
boos!
Error: Out of Bounds
String s="my school";
int x = s.indexOf("c");
What is the value of x?
1
2
4
3
String s1="whatever";
String s2 = s1.substring(1,4);
What is the value of s2?
"hate"
"hat"
"whate"
"what"
Which method would you use to check if two Strings are exactly the same?
equals()
equalsIgnoreCase()
toUpperCase()
toLowerCase()
is this code Good or Bad Java?
String greeting ="hi";
if (greeting == "hello")
{
}
Good
Bad
String s ="Johannesburg"
System.out.print(s.substring(2,5) )
will return:
ohan
han
hann
oha
What is the output of the following code?
String s1 = “Peter Pan”;
String s2 = “Humpty Dumpty”;
System.out.println(s1.compareTo(s2));
0
A positive integer
A negative integer
1
What is the output of the following code?
String s1 = “Peter Pan”;
System.out.println(s1.indexOf(“eter”));
1
2
3
4
What is the output of the following code?
String s1 = “Shakespeare”;
System.out.println(s1.replace(‘s’, ‘P’));
PhakePpeare
phxkeppexre
Shakespeare
All of them
What code forms the basic skeleton of a while loop?
while{….some code…. { …. Some code…}
while { …. Some code…}
while() ….some code…. { …. Some code…}
while( ) { …some code}
Java code to create a non-element array of student marks with the size of 20.
double mark;
double [20] mark = new double;
double [ ] mark = new mark [20];
double [ ] mark = new double [20];
What is the correct relation between length and last-index of array?
last-index is always 1 more than the length
last-index is 1 less than the length (but not always)
last-index is always 1 less than the length
last-index is always equal to the length
Java code to display the size of an array name studentname[ ].
System.out.println("The size is " + studentname[ index ]);
System.out.println("The size is " + studentname.length);
System.out.println("The size is " + length.length);
System.out.println("The size is " + studentname);
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: ");
.......
}
No answer.
temp[ ]
balance
balance [ i ]
An abstract class can implement an interface.
TRUE
FALSE
All methods in an interface are abstract by default.
FALSE
TRUE
A class that extends an abstract class must implement all abstract methods of the superclass.
TRUE
FALSE
An abstract class can have final methods.
TRUE
FALSE
A class can extend multiple abstract classes in Java.
TRUE
FALSE
Which keyword is used to declare an interface in Java?
A. class
B. abstract
C. interface
D. implements
What is an interface in Java?
A. A class with only abstract methods
B. A reference type that contains only constants and abstract methods
C. A class that cannot be extended
D. A class with only concrete methods
Can an abstract class have constructors?
A. Yes
B. No
C. Only if it has abstract methods
D. Only if it is final
Can an interface extend another interface?
A. Yes
B. No
C. Only if it is abstract
D. Only if it is final
What is the main purpose of an abstract class?
A. To provide a base class that other classes can extend and share common functionality
B. To create a class that cannot be extended
C. To create a class with only static members
D. To define multiple classes with the same name
How do you declare an abstract method in Java?
public abstract void methodName();
public void methodName() = 0;
public void abstract methodName();
abstract public void methodName() {}
public static void main(String args[])What does public accomplish?
You can make changes to an object with
methods
attributes
modifiers
parameters
What keyword is used to create an object?
new
create
build
start
main
A method is...
A way of calculating things in Java
A strategy for programming
A predefined set of instructions in a class
A way to sore details in a class
Which among the following best describes encapsulation?
It is a way of combining various data members into a single unit
It is a way of combining various member functions into a single unit
It is a way of combining various data members and member functions into a single unit which can operate on any data
It is a way of combining various data members and member functions that operate on those data members into a single unit
Which inheritance in java programming is not supported
Multiple inheritance
hierarchal inheritance
Multilevel inheritance
Single inheritance
What is subclass in java?
A subclass is a class that extends another class
A subclass is a class declared inside a class
Both above.
None of the above.
If class B is subclassed from class A then which is the correct syntax
class B:A{}
class B extends A{}
class B extends class A{}
class B implements A{}
Find which of the following uses encapsulation?
void main(){
int a;
void fun() { int a=10;
System.out.println(a);
fun(); }
class student{
int a;
public int b; };
class student {
int a;
public void disp(){
System.out.println(a);
} }
static topper() {
char name[10];
public int marks; }
Which of this keyword must be used to inherit a class?
super
this
extent
extends
Which among the following best defines abstraction?
Hiding the implementation
Showing the important data
Hiding the important data
Hiding the implementation and showing only the features
If two classes combine some private data members and provides public member functions to access and manipulate those data members. Where is abstraction used?
Using private access specifier for data members
Using class concept with both data members and member functions
Using public member functions to access and manipulate the data members
Data is not sufficient to decide what is being used
Which keyword is used to implement an interface in Java?
What will be the output of this code?
Compilation error
Method A
Runtime error
No output
What is the default access modifier for methods declared in an interface?
private
public
What keyword is used to inherit from a class and to implement an interface in Java?
inherit, derive
extends, extends
extends, implements
implements, extends
Which of the following correctly distinguishes a class from an interface in Java?
Both classes and interfaces can have constructors
Only interfaces can have constructors
Only classes can have constructors
Neither classes nor interfaces can have constructors
Why can’t interfaces have constructors in Java?
Give an example of a real-world scenario where abstraction is used in Java.
Designing a traffic light system for a city
Developing a recipe management system for a restaurant
Using a bank account class to represent a customer's account
Creating a shopping cart for an online store
Collection of similar classes, interfaces and sub packages
variable
Interface
packages
class
API
applet programming interface
application programming interface
all time program interterface
None
Uses of Packages
easily maintained
access protection
avoid naming collision
None
what is the Syntax to define or create a package?
package <package_name>
package <package_name>;
import package <package_name>;
none
___________ is a collection of prewritten packages, classes, and interfaces with their respective methods, fields and constructors.
API package
class
interface
user defined package
what is syntax to improt all the content of package?
import packaage_name.class_name;
import package_name.*;
import pak1.pak2.pak3;
None
what is syntax to improt a particular class of package?
import class_name.*;
import package_name.*;
import pak1.pak2.pak3;
import packaage_name.class_name;
which member of a class can be accessible by the another class of the same package?
public
private
defualt
protected
which member of a class can be accessible by the class of another package?
public
private
defualt
protected
which member of a class can be accessible by other member of the same class?
public
private
defualt
protected
LIst top level access modifiers
private
package-private
both
none
List member level access modifiers
public
private
default
protected
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);
}
}
1
2
3
4
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?
Yes
No
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;
}
}
Yes
No
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);
}
}
1
2
3
4
In a class, One method has 4 overloaded forms. All have different access modifiers (private, default, protected and public). Is that method properly overloaded?
Yes
No
Method Overriding shows static polymorphism. True or false?
True
False
What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?
Method overloading
Method overriding
Method hiding
None of the mentioned
what is the output
9.0 9.0
9 9
compile time error
none
I am a Person
I am a Student
I am a Person I am a Student
I am a Student I am a Person
What do we call the creation of methods that all have the same name but different implementations?
overloading
inheritance
polymorphism
parameters
What is the output of this program?
1 2
2 1
Runtime Error
Compilation Error
Which import is needed for System.out
java.lang.System
no import is needed
system.out
The correct import for Scanner is the _______ import
java.util.Scanner
java.in.Scanner
java.lang.Scanner
Does Scanner throw an exception, and if so, which one?
Yes, InputException
Yes, IOException
No, no exception is thrown
Which is the correct way to declare an integer variable?
int x = 3;
integer x = 3;
integer x is 3;
int x is 3;
Which is the correct numeric java type to use for decimals?
Integer
Double
Char
Boolean
String
Which variable declaration below is correct?
int a = 4.5;
char grade = 95;
int a = 3/4;
char grade = 'A';
Which of these is not a valid input method?
readInt
readDouble
readChar
readBoolean
Which of the following is a proper way to declare and initialize a variable in Java?
myInteger = 100;
char = 'a';
int myNumber = 10;
"Variable"
Which of the below is not a primitive type in Java?
int
char
boolean
line
double
Which option correctly declares a string variable?
String name = Chris;
string name = "Chris";
string name = 'Chris';
String name = "Chris";
String name = 'Chris';
Which variable name is invalid?
eightName
_8name
8name
$eightname
which one of the following is a legal decelration of a two- dimensional array of integers
int[] a[] = new int[5][];
int[5][5] a = new int[][];
int a = new int[5,5];
int[][] a = new int[][5];
A class that is inherited is called a ______ .
superclass
Subclass
subsetclass
Relativeclass
This is a general structure a method.
<Returnvalue type> <Method Name> (argument / s)
<Modifier> < type> <Method Name> (parameter / s)
public static void main (String[ ] args)
<Method Name> (parameter)
Describe method.
A component of a program in a big program.
A program to perform a specific task.
A component of a program written to perform a specific task.
A variable that use to read an input.
Which of the following is not a Java features?
Dynamic
Architecture Neutral
Use of pointers
Object-oriented
Which of the following option leads to the portability and security of Java?
Bytecode is executed by JVM
The applet makes the Java code secure and portable
Use of exception handling
Dynamic binding between objects
What does the expression float a = 35 / 0 return?
0
Not a Number
Infinity
Run time exception
