public class Program
{
public static void main(String[] args) {
Program p=new Program();
p.start();
}
void start(){
long[] a={3,4,5};
long[] b=method(a);
System.out.println(a[0]+a[1]+a[2]);
System.out.println(b[0]+b[1]+b[2]);
}
long[] method(long[] c){
c[1]=7;
return c;
}
}
A) 12
15
B) 15
12
C) 12
12
D) 15
15
{
public static void main(String[] args) {
Program p=new Program();
p.start();
}
void start(){
long[] a={3,4,5};
long[] b=method(a);
System.out.println(a[0]+a[1]+a[2]);
System.out.println(b[0]+b[1]+b[2]);
}
long[] method(long[] c){
c[1]=7;
return c;
}
}
A) 12
15
B) 15
12
C) 12
12
D) 15
15
public class Program
{
public static void main(String[] args) {
int index=0;
boolean flag=true;
boolean reg1=false,reg2;
reg2=(flag |((index++)==0));
reg2=(reg1|(index+=2)>0);
System .out.println(index );
}
}
A) 0
B) 1
C) 2
D) 3
{
public static void main(String[] args) {
int index=0;
boolean flag=true;
boolean reg1=false,reg2;
reg2=(flag |((index++)==0));
reg2=(reg1|(index+=2)>0);
System .out.println(index );
}
}
A) 0
B) 1
C) 2
D) 3
class Train{
int speed=10;
public void getSpeed(){
System.out.println(speed);
}
public void setSpeed(int speed ){
this.speed=40;
speed=this.speed;
}
}
class BulletTrain extends Train {
int speed =20;
public void getSpeed(){
System.out.println(super.speed);
}
}
public class Program
{
public static void main(String[] args) {
Train train=new BulletTrain();
train.setSpeed(50);
train.getSpeed();
}
}
int speed=10;
public void getSpeed(){
System.out.println(speed);
}
public void setSpeed(int speed ){
this.speed=40;
speed=this.speed;
}
}
class BulletTrain extends Train {
int speed =20;
public void getSpeed(){
System.out.println(super.speed);
}
}
public class Program
{
public static void main(String[] args) {
Train train=new BulletTrain();
train.setSpeed(50);
train.getSpeed();
}
}
import java.util.*;
public class Program
{
public static void main(String[] args) {
HashSet<Integer> h=new HashSet<>();
h.add(null);
h.add(null);
h.add(100);
h.add(300);
h.add(400);
h.add(null);
h.add(100);
h.add(300);
Object[] o=h.toArray();
System.out.println(Arrays.toString(o));
}
}
public class Program
{
public static void main(String[] args) {
HashSet<Integer> h=new HashSet<>();
h.add(null);
h.add(null);
h.add(100);
h.add(300);
h.add(400);
h.add(null);
h.add(100);
h.add(300);
Object[] o=h.toArray();
System.out.println(Arrays.toString(o));
}
}
Options for above program
Anonymous Quiz
25%
[null,400,100,300]
25%
[null,null,100,300,400,null,100,300]
40%
Compilation Problem
10%
None of these
public class Program
{
public static void main(String[] args) {
try{
int sum=5;
for(int i=-1;i<5;++i){
sum=sum/i;
}
}catch(ArithmeticException e){
System.out.println("0");
}
System.out.println(sum);
}
}
{
public static void main(String[] args) {
try{
int sum=5;
for(int i=-1;i<5;++i){
sum=sum/i;
}
}catch(ArithmeticException e){
System.out.println("0");
}
System.out.println(sum);
}
}
Which method will contain the block of code to be executed when thread starts?
Anonymous Quiz
37%
Main
26%
Start
7%
Execute
30%
Run
public class Program
{
static double overloadedMethod(int i,double d){
return d *= i;
}
static double overloadedMethod(double d,int i){
return i += d;;
}
public static void main(String[] args) {
System.out.println(overloadedMethod(100,100));
}
}
{
static double overloadedMethod(int i,double d){
return d *= i;
}
static double overloadedMethod(double d,int i){
return i += d;;
}
public static void main(String[] args) {
System.out.println(overloadedMethod(100,100));
}
}
Options For above program
Anonymous Quiz
32%
Compilation Error
24%
Runtime Error
28%
10000
12%
10000.0
4%
200
For listing the objects within an ArrayList, which of the following options are available.
1) An Iterator
2) A ListIterator 3) An Enumeration
1) An Iterator
2) A ListIterator 3) An Enumeration
Anonymous Quiz
8%
1
31%
1 and 2
54%
1 and 2 and 3
8%
1 and 3
class Parent{
public int index=1;
}
public class Program extends Parent
{
public Program(int index){
index=index;
}
public static void main(String[] args) {
Program p=new Program(10);
System.out.println(p.index);
}
}
public int index=1;
}
public class Program extends Parent
{
public Program(int index){
index=index;
}
public static void main(String[] args) {
Program p=new Program(10);
System.out.println(p.index);
}
}
public class Program
{
int val;
public Program(int _val){
val=_val;
}
public static void main(String[] args) {
Program p=new Program();
Program p=new Program(10);
}
}
{
int val;
public Program(int _val){
val=_val;
}
public static void main(String[] args) {
Program p=new Program();
Program p=new Program(10);
}
}
Options for above program
Anonymous Quiz
35%
Compilation error due to missing default constructor
20%
Compilation error due to constructor having a return type
35%
Compilation error due to missing parameterized constructor
10%
No Compilation Error. Object a has Val value of 0(zero) while object b has val value of 20
import java.util.ArrayList;
public class Program
{
public static void main(String[] args) {
ArrayList a=new ArrayList();
a.add("C");
a.add("E");
a.add("B");
a.add("D");
a.add("A");
a.add("Z");
a.add("M");
a.remove(1);
a.remove(3);
a.add(2,a.get(3));
a.add(a.size()+" ");
a.remove(3);
System.out.println(a);
}
}
public class Program
{
public static void main(String[] args) {
ArrayList a=new ArrayList();
a.add("C");
a.add("E");
a.add("B");
a.add("D");
a.add("A");
a.add("Z");
a.add("M");
a.remove(1);
a.remove(3);
a.add(2,a.get(3));
a.add(a.size()+" ");
a.remove(3);
System.out.println(a);
}
}
Options for above program
Anonymous Quiz
11%
E,A,B,Z,M,6
29%
E,A,Z,M,5
18%
C,A,Z,M,5
25%
C,B,Z,Z,M,6
18%
None of these