0 of 10 Questions completed
Questions:
You have already completed the task before. Hence you can not start it again.
Task is loading…
You must sign in or sign up to start the task.
You must first complete the following:
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Your test has been submitted. Feel free to close the page, we will get the result back to you later, thank you!
Predict the output of following Java Programs:
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);
}
}
Is there any compiler error in following Java Program?
// filename Test.java
class
Test {
public
static
void
main(String[] args) {
for
(
int
i =
0
;
1
; i++) {
System.out.println(
"Hello"
);
break
;
}
}
}
Which of following java programs have no errors?
What is the value of k after the following program finishes?
// filename Main.java
class Main {
public static void main(String args[]) {
int k =0;
for (byte i = ‘0’; i < 300 ; i++, k++) {
System.out.println(k);
}
}
}
What is the outcome of this program?
import java.util.*;
public class ListExample1{
public static void main(String args[]){
//Creating a List
List<String> list=new ArrayList<String>();
//Adding elements in the List
list.add(“Mango”);
list.add(“Apple”);
list.add(“Grapes”);
//Iterating the List element using for-each loop
for(String fruit:list){
list.add(“Cake’”);
System.out.println(fruit);
}
}
}
What is the output of this program?
public
class
Test
{
public
static
void
main(String[] args)
{
StringBuilder s1 =
new
StringBuilder(
"Java"
);
String s2 =
"Love"
;
s1.append(s2);
s1.substring(
4
);
int
foundAt = s1.indexOf(s2);
System.out.println(foundAt);
}
}
What is the print of this program?
class
Alpha
{
public
String type =
"a "
;
public
Alpha() { System.out.print(
"alpha "
); }
}
public
class
Beta
extends
Alpha
{
public
Beta() { System.out.print(
"beta "
); }
void
go()
{
type =
"b "
;
System.out.print(
this
.type +
super
.type);
}
public
static
void
main(String[] args)
{
new
Beta().go();
}
}
What is the outcome of this program?
public
class
MyStuff
{
String name;
MyStuff(String n) { name = n; }
public
static
void
main(String[] args)
{
MyStuff m1 =
new
MyStuff(
"guitar"
);
MyStuff m2 =
new
MyStuff(
"tv"
);
System.out.println(m2.equals(m1));
}
@Override
public
boolean
equals(Object obj)
{
MyStuff m = (MyStuff) obj;
if
(m.name !=
null
) {
return
true
; }
return
false
;
}
}
What is the output of this program?
public
class
Calculator
{
int
num =
100
;
public
void
calc(
int
num) {
this
.num = num *
10
; }
public
void
printNum() { System.out.println(num); }
public
static
void
main(String[] args)
{
Calculator obj =
new
Calculator();
obj.calc(
2
);
obj.printNum();
}
}
What is the output of the following program?
// Main.java
public
class
Main
{
public
static
void
main(String args[])
{
String s1 =
"abc"
;
String s2 = s1;
s1 +=
"d"
;
System.out.println(s1 +
" "
+ s2 +
" "
+ (s1 == s2));
StringBuffer sb1 =
new
StringBuffer(
"abc"
);
StringBuffer sb2 = sb1;
sb1.append(
"d"
);
System.out.println(sb1 +
" "
+ sb2 +
" "
+ (sb1 == sb2));
}
}
//end class