Font size
WorksheetsCode A Thone Finals
Total questions: 45
Worksheet time: 41mins
Which operator cannot be used with if-else statement?
<=
||
&&
? :
Predict the output of the following code snippet:
int a = 1;
int b = 2;
if (a == b)
System.out.println("Both values are equal");
else
System.out.println("Values are not equal");
Consider the following code snippet: if ( c > d) x = c; else x = d; Choose the correct option if the code mentioned above is rewritten using the ternary operator:
x = (c > d) ? c : d;
x = (c > d) ? d : c;
x = (c > d) ? c : c;
x = (c > d) ? d : d;
Consider the following code snippet: int val = 2; switch (val) { case 1: System.out.println("Case 1"); break; case 2: System.out.println("Case 2"); break; default: System.out.println("No match found"); break; } Which of the following statements is correct?
Any number of values
2 values
Only 1 value
3 values
Give the output of the Math.abs(x); when x = -9.99
-9.99
9.99
0.99
None
Which of the following is false to find square of a number?
Math.pow(a,2)
a*a
Math.sqrt(a,2)
All of the above
If a, b and c are the sides of a triangle then which of the following statement is true for: if(a!=b && a!=c && b!=c)?
Equilateral triangle
Scalene triangle
Isosceles triangle
All of the above
To execute a loop 10 times, which of the following statement satisfies:
for(i=6;i<=26;i=i+2)
for(i=3;i<=30;i=i+3)
for(i=0;i<10;i=i++)
all of the above
Give the output of the following snippet based on nested loops- int i,j; for (i=0; i<4; i++) { for (j=i; j>=0; j--) System.out.print(j); System.out.println();
Name the type of error- "Division by a variable that contains a value of zero"
True
False
Which of these components are used in a Java program for compilation, debugging, and execution?
JDK
JVM
JRE
JIT
The binary equivalent of hexadecimal digit E is
(a)
Predict the output of the following-
String str = "Computer Applications" + 1 + 0;
System.out.println("Understanding" + str);
Predict the output-
boolean p;
p = ("BLUEJ".length() > "bluej".length()) ? true: false;
Predict the output-
String str1 = "Information Technology";
String str2 = "information technology";
boolean p = str1.equalsIgnoreCase(str2);
System.out.println("The result is " + p);
What will be the value stored in the variable 'c' if the following statement is executed?
c = "COMPUTER".charAt("COMPUTER ".indexOf('P'))
(a)
What will be the output of the following program snippet?
s1 = "COMPUTER";
s2 = "computer";
System.out.println(s1.equals(s2));
What will be the output of the following program snippet?
str1 = "AMAN";
str2 = "AMIT";
System.out.println(str1.compareTo(str2));
Predict the output-
String str = "Information Technology";
int p;
p = str.indexOf('n');
System.out.println(p);
What was Java originally designed for?
Interactive TV
Internet
Gaming
Cars
The
operator who also acts as a string concatenation _______
a)
/
b) *
c)
+
d) –
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?
===============
#################
&&&&&&&&&
&&&&&&&&&&&
===============
#################
Syntax
of the class variables________
Class_name.class_variables
public
static void main (String arg [])
Class_name
object_name;
Class
name_anyRef;
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
JAVA
does not directly implement____________
Multiple
inheritance
Multilevel inheritance
Hybrid inheritance
Single inheritance
The
interface item would inherit both the
constants-----------------------and---------------------
Code, Variable
Code, Name
Code, Method
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
How to
block the thread exceptions
Sleep()
Start()
Stop()
Run()
When the
applet is terminated _________and________ methods are called sequence
run()
and destroy()
stop()
and destroy()
run()
and stop()
none
what is
the purpose of for loops in applet?
circles
triangle
rectangle
square
Which company owns Java?
Oracle
Microsoft
Apple
Intel
Consider the following operation performed on a stack of size 5.
Push(1);
Pop();
Push(2);
Push(3);
Pop();
Push(4);
Pop();
Pop();
Push(5);
After the completion of all operation, the number of elements present in stack are
a)1
b)2
c)3
d)4
Two lists, A and B are implemented as singly linked link-lists. The address of the first and last node are stored in variables firstA and lastA for list A and firstB and lastB for list B. Given the address of a node is given in the
variable node, the element stored in the node can be accessed by the
statement node->data and the address to the next node can be accessed by node->next. Pankaj wants to append list B at end of list A. Which of the following
statements should he use?
Op 1: lastB -> next = firstA
Op 2: lastA = firstB
Op 3: lastA->next = firstB
Op 4: lastB = firstA
What would be the answer to this expression tree?
28
27
31
29
-Contains no duplicate elements.
-Can contain at most one Null value.
-Elements are not key-value pairs.
-Accessing an element can be almost as fast as performing a similar operation on an array.
Which of these classes provides the specified features?
LinkedList
TreeMap
HashSet
LinkedHashMap
HashMap
Nodes in a linked list contain two things
Direction and a pointer
Data and a pointer
A Pointer and a reference
A pointer and a node
The situation when in a linked list Head==NULL
is
Full
Empty
Half full
saturated
In the above image what will be printed when Head->next->data?
83
9
27
Error
Complete the code in the red column
string info; int link;
int info; NodeType link;
int info; string link;
int info; NodeType * link;
