Font size
WorksheetsOOP - Fast Track Exam - 23.01.2021
Total questions: 150
Worksheet time: 1hrs 19mins
A __________ is the physical/logical entity.
Thing
Objects
Classes
Behavior
Below are the list of three characteristics of an Object EXCEPT ONE. What is it?
Behavior
Attribute
State
Identity
REALME - ASUS - ANDROID PHONE - HUAWEI - SAMSUNG - MOBILE PHONE
In the list above, what are the sample of objects?
REALME, ASUS, ANDROID PHONE, HUAWEI
MOBILE PHONE, SAMSUNG, ANDROID PHONE, ASUS
ASUS, REALME, HUAWEI, SAMSUNG
SAMSUNG, MOBILE PHONE, ASUS, REALME
What are the sample of classes in the list below?
Programming Language
Python
Java
C++
A keyword used to initialize an object.
OLD
CLONE
METHOD
NEW
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
If data members are private, what can we do to access them from the class object?
Create public member functions to access those data members
Create private member functions to access those data members
Create protected member functions to access those data members
Private data members can never be accessed from outside the class
Which feature can be implemented using encapsulation?
Inheritance
Abstraction
Polymorphism
Overloading
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 of this keyword must be used to inherit a class?
super
this
extends
extent
A class member declared protected becomes a member of subclass of which type?
public member
private member
protected member
static member
class A
{
int i;
void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
void display()
{
System.out.println(j);
}
}
class inheritance_demo
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
0
1
2
Compilation Error
What will be the output of the following Java program?
class A
{
int i;
}
class B extends A
{
int j;
void display()
{
super.i = j + 1;
System.out.println(j + " " + i);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
2 2
3 3
2 3
3 2
Using which of the following, multiple inheritance in Java can be implemented?
Interfaces
Multithreading
Protected methods
Private methods
In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
Protected
Private
Public
Static
If super class and subclass have same variable name, which keyword should be used to use super class?
super
this
upper
classname
Which inheritance in java programming is not supported
Multiple inheritance using classes
Multiple inheritance using interfaces
Multilevel inheritance
Single inheritance
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{}
Order of execution of constructors in Java Inheritance is
Base to derived class
Derived to base class
Random order
none
Output of following Java Program?
10
20
Compilation Error
Run Time Error
Output of following Java Program?
12
321
123
23
Which inheritance in java programming is not supported
Multiple inheritance using classes
Multiple inheritance using interfaces
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.
Which line of code prints out "Hello World"?
System.out.println("Hello World");
system.out.println("Hello World");
System.out.println(Hello World);
System.out.printline("Hello World");
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
What is the parent class of All Exceptions in JAVA
Throw
Exception
Error
Bug
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
try block may or may not contains catch blocks
True
False
What is the purpose of 'throw' keyword
To Raise an exception explicityly
To Raise an exception implicityly
To create user defined exceptions
To create custom exceptions
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
How to create our own exception
using 'throw' keyword
using 'throws' keyword
using 'finally' keyword
using 'throwable' keyword
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Which of these keywords is not a part of exception handling?
try
finally
thrown
catch
java.lang.NullPointerException is a
Error
runtime exception
Compile time exception
None
Which of these class is highest in hierarchy in java
java.lang.Exception
java.lang.Error
java.lang.Throwable
java.lang.Object
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
What will it print?
1
2
3
30
1
2
30
1
2
3
11
1
2
11
How many except statements can a try-except statement have?
None
One
Two
Multiple
When is the finally block executed?
when an exception occurs
when no exception occurs
never
always
When will the else part of try-except-else be executed?
always
when an exception occurs
when no exception occurs
never
Can one except block handle multiple exceptions?
Yes
No
May be
Insufficient information
The ZeroDivisionError may occur during which operation(s)?
Division
Modulo
Both
None
Which of the following is FALSE about arrays on Java
A java array is always an object
Length of array can be changed after creation of array
Arrays in Java are always allocated on heap
Predict the output?
public class Main {
public static void main(String args[]) {
int arr[] = {10, 20, 30, 40, 50};
for(int i=0; i < arr.length; i++)
{
System.out.print(" " + arr[i]);
}
}
}
10 20 30 40 50
Compiler Error
10 20 30 40
class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
0
0
garbage value
garbage value
Compiler Error
Exception
public class Main {
public static void main(String args[]) {
int arr[][] = new int[4][];
arr[0] = new int[1];
arr[1] = new int[2];
arr[2] = new int[3];
arr[3] = new int[4];
int i, j, k = 0;
for (i = 0; i < 4; i++) {
for (j = 0; j < i + 1; j++) {
arr[i][j] = k;
k++;
}
}
for (i = 0; i < 4; i++) {
for (j = 0; j < i + 1; j++) {
System.out.print(" " + arr[i][j]);
k++;
}
System.out.println();
}
}
}
Compiler Error
0
1 2
3 4 5
6 7 8 9
0
0 0
0 0 0
0 0 0 0
9
7 8
4 5 6
0 1 2 3
Which of the following is the correct way of importing an entire package ‘pkg’?
import pkg.
Import pkg.
import pkg.*
Import pkg.*
Which of the following is/are advantages of packages?
Packages avoid name clashes
Classes, even though they are visible outside their package, can have fields visible to packages only
We can have hidden classes that are used by the packages, but not visible outside.
All of the above
Which of these is a mechanism for naming and visibility control of a class and its content?
Object
Packages
Interfaces
None of the above
Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?
Public
Protected
No Modifier
All of the mentioned
Arrays in Java are dynamically allocated using the . . . . operator.
create
dynamic
arrayList
new
Which of the following statements correctly declares a two-dimensional integer array?
int Matrix[ ] = new int[5,4];
int Matrix[ ]; Matrix = new int[5,4];
int Matrix[ ][ ] = new int[5][4];
int Matrix[ ][ ] = int[5][4];
1. The capability to control the access of multiple threads to any shared resource is called_____________
Synchronization
Multitasking
multithreading
None
Why to use synchronization?
Avoiding thread interference
Avoiding consistency problem
Both
None
_______________ and __________________ are the types of synchronization.
Process synchronization and thread synchronization
multitasking and multithreading
Interthread communication and mutual exclusion
None
How many Types of synchronization approaches are there under mutual exclusion?
3
4
2
0
What are the approaches under mutual exclusion?
Synchronized method
Synchronized block
Static synchronization
All the above
Choose the correct syntax for synchronized method.
a. synchronized returntype methodname(.....)
a. returntype methodname(.....)
c. synchronized methodname(.....)
d. None
Identify the correct mutual exclusion approach:
synchronized(this)
{
….
….
}
Synchronized method
Synchronized block
Static Synchronization
None
Identify the correct mutual exclusion approach:
synchronized static returntype method(parameters)
{
}
synchronized method
synchronized block
static synchronization
None
__________________________ is a mechanism in which a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed.It
Inter thread communication
Co-operation
option 1 or option 2
None
_____________tells calling thread to give up monitor and go to sleep until some other thread enters the same monitor and call notify.
wait()
notify()
notifyAll()
start()
______________wakes up a thread that called wait() on same object.
start()
run()
notify()
sleep()
_________wakes up all the threads that called wait() on same object.
notify()
notifyAll()
wait()
sleep()
Which is the static method?
wait()
sleep()
Both
None
wait(), notify() and notifyAll() belongs to which class?
Thread
Object
FileInputStream
Exception
_________thread in java is a service provider thread that provides services to the user thread.
Producer thread
Consumer thread
Daemon thread
None
Daemon thread is a _________priority thread.
low
high
Normal
None
wait() releases the lock on the shared resource.
True
False
_______________is the return type of isDaemon()
String
int
boolean
float
sleep() method belongs to which class?
Object
Thread
Exception
InputStream
We should notify the sleep() method to wake up.
True
False
Execution of a java thread begins on which method call?
Run ()
Start ()
Execute ()
Launch ()
How many ways a thread can be created in Java multithreading?
1
2
5
10
Which method is used to make main thread to wait for all child threads
Join ()
Sleep ()
Wait ()
Stop ()
Default value of a java thread is
0
1
5
10
If a priority of a java thread is 3 then the default priority of its child thread will be
0
1
5
3
Daemon thread runs in
BackGround
Foreground
Both
none
Which method is used to wait for child threads to finish in Java?
Wait ()
Sleep ()
Join ()
isAlive()
Which will contain the body of the thread in Java?
Start()
Run()
Main()
Execute()
The life cycle of a thread in java is controlled by
JRE
JDK
JVM
None
Which method is used to get current running thread object?
runningThread()
currentThread()
runnableThread()
None
Synchronized static methods acquire lock on
Class
Object
Interface
None
Thread priority in Java is?
Integer
Float
Double
Long
The life cycle of thread in JAVA is controlled by
JDK
JVM
JRE
None
In JAVA multi threading, a thread can be created by_______
Extending class
Implementing Runnable Interface
both
none
Which statements is/are correct
On calling Thread start ( ) method a new thread is created
Thread start( ) method call run( ) method internally
Thread run( ) method can also be called directly to create thread
both a & b
The following example shows the creation of a
import java.applet.*;
import java.awt.*;
public class Main extends Applet{
public void paint(Graphics g){
g.drawString("Welcome in Java Applet.",40,20);
}
}
a. Banner using Applet
b. Basic Applet
c. Display clock
d. None of the above
The APPLET tag is used to start an applet from both an HTML document and from an applet viewer.
a. True
b. False
What invokes immediately after the start() method and also any time the applet needs to repaint itself in the browser?
a. stop()
b. init()
c. paint()
d. destroy()
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet {
public void paint(Graphics g) {
g.drawString("A Simple Applet", 20, 20);
}
}
a) A Simple Applet
b) A Simple Applet 20 20
c) Compilation Error
d) Runtime Error
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet {
Graphic g;
g.drawString("A Simple Applet", 20, 20);
}
a) 20
b) Default value
c) Compilation Error
d) Runtime Error
How would you change the text of a label to the text contained by an integer named num;
label.setText(num);
label.updateText(num);
label.setTest("num");
label.setText(num+ "");
What object type handles Java's layouts?
Layout Manager
Layout Scheduler
Layout Operator
Layout Director
What is the purpose of the line of code:
import java.awt.*;
To allow you to make Random number generators
To use an interface.
To import a package
To allow you to Scan from the terminal or a file.
What is a method?
An organized and functionally based set of related interfaces and classes
Where we type our code.
A set of group of code that can be called for execution.
An instance of a class
Which of the lines of code DOES NOT call a method?
frame.setSize()
frame.setVisible(true);
JFrame frame;
frame.setResizable(false);
JFrame, JPanel, JLabel, JButton are examples of ...
methods
classes
interfaces
packages
What code adds this JButton to this JPanel?
JPanel panel = new JPanel();
JButton button = new JButton();
panel.add(button);
button.add(panel);
frame.add(panel);
panel.add(JButton);
Which of the options below correctly set the background color of a JPanel called panel to the color blue? (More than one option may be correct).
panel.setBackground(0,0,255);
panel.setBackground(BLUE);
panel.setBackground(new Color(0,0,255);
panel.setBackground(Color.BLUE);
panel.addBackgroundColor(BLUE);
Which of the following layouts would be good to use for GUI that resembles a computer keyboard?
Flow Layout
Border Layout
Grid Layout
Null Layout
Which of the following layouts would be good to use for GUI that resembles picture frame, with a big picture on the inside and little buttons around the outside?
Flow Layout
Border Layout
Grid Layout
Null Layout
Which of the following layouts would be good to use for GUI that adjusts the position of objects when the screen is resized?
Flow Layout
Border Layout
Grid Layout
Null Layout
Which of the following layouts would be good to use for manually placing objects on a GUI?
Flow Layout
Border Layout
Grid Layout
Null Layout
To "nest" layouts means to...
set up the panel like a bird's nest
put a panel with a layout inside another panel with a layout
the panel will have a hole in the middle for a bird to lay an egg
(this is a made up term. You didn't teach this).
Which items below are interfaces?
ActionListener
JPanel
KeyListener
IOException
What method(s) must we include in order to implement ActionListener?
paintComponent
actionEvent
actionPerformed
keyPressed
What method(s) must we include in order to implement KeyListener?
keyTyped
keyPressed
keyReleased
keyUsed
What code must be included in order for a class to implement ActionListener and for a JButton click to be listened to? (select all that apply)
public class question17 implements ActionListener{...}
public void actionPerformed(ActionEvent e){ .. }
JButton button = new JButton();
button.addActionListener(this);
Nothing needs to be added. Your normal code implements ActionListener.
How can we figure out which button was clicked inside our actionPerformed?
e.getSource()
e.getSource
getSource()
getButtonClicked()
e.getButtonClicked()
In order to make a class that inherits characteristics of JPanel, we need to use the key word...
public
class
extends
implements
throws
In Pong, when we drew shapes inside of our main JPanel, we overrode which method?
paintComponent
actionPerformed
repaint
keyPressed
On a 1000 x 800 pixel JFrame, when we run the line of code below what shape appears on the screen?
g.fillRect(500,400, 30, 30);
A filled in square that is 30 pixels by 30 pixels.
A filled in rectangle that is 500 pixels wide by 400 pixels in height.
A filled in rectangle that is 400 pixels wide by 500 pixels in height.
The border of a rectangle that is 500 pixels wide by 400 pixels in height.
On a 1000 x 800 pixel JFrame, when we run the line of code below where on the screen will the shape appear?
g.fillRect(500,400, 30, 30);
The center of the rectangle will be at the coordinate 500,400
The bottom right of the rectangle will be at the coordinate 30, 30
The top left of the rectangle will be at the coordinate 500,400
The top right of the rectangle will be at the coordinate 500,400
On a 1000 x 800 pixel JFrame, when we run the line of code below where on the screen will the shape appear?
g.fillRect(100, 700, 50, 100);
top right
top left
bottom right
bottom left
On a 1000 x 800 pixel JFrame, when we run the line of code below what does the rectangle look like?
g.fillRect(100, 700, 50, 100);
twice as wide as it is tall.
twice as tall as is wide.
it's a square.
7 times as tall as it is wide.
Which method do we use to put text onto a panel?
g.drawString(...)
g.setText(...)
g.setColor(...)
g.fillRect(...)
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);
Which is correct method to convert String into uppercase
changeUpperCase()
convertUpperCase()
toUpper()
toUpperCase()
String txt = "Hello World";
System.out.println(txt.toUpperCase());
Choose the correct output.
"HELLO WORLD"
HELLO WORLD
Hello world
Hello World
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"
What will be the output of below code?
String statement = "Outfit of the day";
System.out.println(statement.Substring(3,6));
it of
tfit
fit
FIT
Choose most appropriate purpose of trim() method in String?
to remove white spaces
to get a substring of the string
to cut String at desired index
to remove extra white spaces from start and end of String
What is the return type of equalsIgnorecase() method?
int
String
char
boolean
What is the most appropriate way to check if two Strings are identical?
string1 == string2
string1.equals(string2)
string1.same(string2)
string1.equalsIgnorecase(string2)
(Multiple answer question)
Pick all NON-primitive datatypes from below :
String
int
primitive
Array
int[] myArray = {11, 22, 33, 44, 55};
which code is correct to print length of above int-array?
System.out.println(int[].myArray.length());
System.out.println(myArray.length);
System.out.println(myArray.length());
System.out.println(int[].myArray.size());
String[] friends = {"John", "Mike", "Samantha", "Monica"};
which code is correct to print "Samantha" using array functionality?
System.out.println(friends[2]);
System.out.println(friends[3]);
System.out.println(friends["Samantha"]);
System.out.println(friends{2});
Select correct code to create an array of "double" datatype of length 5.
double arr = double[5];
double{} arr = new double{5};
double[5] arr = new double[];
double[] arr = new double[5];
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
