Font size
WorksheetsJava
Total questions: 61
Worksheet time: 31mins
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.
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)
In which line is representing the meaning of Standard library method.
Line 2
Line 8
Line 13
Line 10
The different between static and non static method is ....
for non static method : user need to create object in a class to call a method.
A method is to perform only specific task.
There is no significant differences between static and non - static method.
Both are bounded with a class.
This program is consist with syntax error. Identify the reason and fix the error with the most suitable answer.
Mismatched with data type of radius and height.
FIx with :- char radius, height;
Mismatched with data type of r and h in method.
FIx with :- int r, h;
Mismatched with variable name of radius and height.
FIx with :- double r, h;
Mismatched with data type of radius and height.
FIx with :- double radius, height;
Is String a primitive data type?
Yes
No
Both
Which method to use to find length of a string?
length()
size()
long()
count()
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);
String txt = "Hello World";
System.out.println(txt.toUpperCase());
Choose the correct output.
"HELLO WORLD"
HELLO WORLD
Hello world
Hello World
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
The following Syntax is used for?
class Subclass-name extends Superclass-name
{
//methods and fields
}
Polymorphism
Encapsulation
Inheritance
None of the above
A class that is inherited is called a ______ .
superclass
Subclass
subsetclass
Relativeclass
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
try block may or may not contains catch blocks
True
False
How to create our own exception
using 'throw' keyword
using 'throws' keyword
using 'finally' keyword
using 'throwable' keyword
Choose the CORRECT exception
String department="JTMK";
Integer no=Integer.parseInt(department);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundsException
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
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()
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
Thread priority in Java is?
Integer
Float
Double
Long
Object may be communicate --------------
Through object
Through class
Through methods
Through
data
Consider
the following Java program :
public class Compute {
public static void main (string args [ ])
{
int result, x ;
x = 1 ;
result = 0;
while (x < = 10) {
if (x%2 == 0) result + = x ;
+ + x ;
}
System.out.println(result) ;
}
}
Which of the following will be the output of the above program?
55
30
25
35
Which of
the following variable declaration would NOT compile in a java program?
int
var;
int VAR;
int var1;
int
1_var;.
Which
one is java token?
Identifiers
Operators
Literals
all the
above
What
will be printed as the output of the following program?
public class testincr
{
public static void main(String args[])
{
int i = 0;
i = i++ + i;
System.out.println(“I = ” +i);
}
}
I=0
I=1
I=2
Error
The
operator who also acts as a string concatenation _______
a)
/
b) *
c)
+
d) –
What is the type and value of the following expression? (Notice the integer
division)
-4 + 1/2 + 2*-3 + 5.0
int -5
double
-4.5
int
-4
double
-5.0
Use the
following declaration and initialization to evaluate the Java
expressions
int a = 2, b = 3, c = 4, d = 5;
float k = 4.3f;
System.out.println (c=c++);
2
4
5
8
Predict
the output of following Java Programs.
// filename Main.java
class Test {
protected int x, y;
}
class Main {
public static void main(String
args[]) {
Test t = new Test();
System.out.println(t.x +
" " + t.y);
}
}
1,1
1,2
0,0
Error
What is
casting a value?
expression
ratio
operator
all of the above
Consider the following Java program :
class IfStatement{
public static void main(String args[])
{
int a=2, b=3;
if (a==3)
if (b==3)
System.out.println(“===============”);
else
System.out.println(“#################”);
System.out.println(“&&&&&&&&&&&”);
}
}
Which of the following will the output be?
===============
#################
&&&&&&&&&
&&&&&&&&&&&
===============
#################
The
general form of constructing an array is _______
Datatype
arr-name [];
Datatype
[]arr-name;
arr-name=
new datatype[noOfElements];
arr-name.length
Which is
one of the symbol of array?
{ }
( )
[ ]
< >
Consider
the following class definition:
public class MyClass
{
private int value;
public void setValue(int i){ / code / }
// Other methods…
}
The method setValue assigns the value of i to the instance field value.
What could you write for the implementation of setValue?
value = i;
this.value = i;
value == i;
Both
(A) and (B) and above
What is
a keyword used in extending interfaces?
Extern
Extend
Extnd
extends
Predict
the output of following Java programs.
package main;
class Base {
public void Print() {
System.out.println("Base"); }
}
class Derived extends Base {
public void Print() {
System.out.println("Derived");
} }
class Main{
public static void DoPrint( Base
o ) {
o.Print();
}
public static void main(String[]
args)
{ Base x = new Base();
Base y = new Derived();
Derived z = new Derived();
DoPrint(x);
DoPrint(y);
DoPrint(z);
} }
Base,
Derived, Derived
Derived,
Derived ,Derived
Derived,
Derived, Base
None
Expand
API
Application
programming interface
Advanced programming interface
Architecture programming interface
Artificial programming interface
Multithreading
concept can be divided into _________
Class
Processes
Method
Object
Applet
program are used to the ----------------
Internet computing
Cloud Computing
Grid Computing
Green Computing
The
Graphics object g is an argument of -------------------------
Print()
Applet()
Graphics()
paint()
which is
one of the initialization state?
int()
init()
initial()
inti()
what is
the executable applet?
.class
.object
.method
.function
which is
used for graphics object?
<g>
(g)
g.
,g
The keyword "method" is another name for
an object
a class
a function
a variable
Which of the following is incorrect?
int count = 50.0;
int salary = 50_000;
int salary = 50_00;
all of these are incorrect
The numeric type int uses how many bits?
16
32
48
64
What would the new value of A be?
A=1;
a++;
1
2
3
4
What does the following code output?
int x = 1;
System.out.println(x++);
1
2
compilation error
runtime error
If a=2, b=5, c=3
Find result for : 8 * (a + b + c) – a % c
80
81
77
78
int a = 2, b = 2, c = 0;
double d = 30.1;
Find answer for = (a > b) &&(( c <d) || (c!=a))
35.9
80
true
false
int a = 2, b = 2, c = 0;
double d = 30.1;
Find answer for = (a > b) &&(( c <d) || (c!=a))
35.9
80
true
false
When was Java released?
1975
1994
1995
1996
1997
In which line is representing the meaning of Standard library method.
Line 2
Line 8
Line 13
Line 10
