JAVA
2.7K subscribers
73 photos
111 files
76 links
Download Telegram
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); } }
Anonymous Quiz
19%
0
48%
1
10%
2
10%
3
14%
Compile time error
To prevent any method from overriding, we declare the method as,
Anonymous Quiz
21%
Static
8%
Const
38%
Final
21%
Abstract
13%
None of these
The fields in an interface are implicitly specified as,
Anonymous Quiz
15%
static only
4%
Protected
15%
Private
58%
Both static and final
8%
None of the above
public class testmeth
{
static int i = 1; public static void main(String args[]) { System.out.println(i+” , “); m(i); System.out.println(i); } public void m(int i) { i += 2; } }
Anonymous Quiz
25%
1,3
25%
3,1
15%
1,1
15%
1,0
20%
None of the above
public class Program
{
public static void main(String[] args) { int x=3,y=5,z=10; System.out.println(++z+y-y+z+x++); } }
Anonymous Quiz
26%
24
17%
23
22%
20
35%
25
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
Options for above program
Anonymous Quiz
18%
A
50%
B
23%
C
9%
D
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
Options for above program
Anonymous Quiz
21%
A
21%
B
33%
C
25%
D
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();
}
}
Options for above program
Anonymous Quiz
14%
50
33%
40
29%
30
14%
20
10%
10
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) {
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);
}
}
Options for above program
Anonymous Quiz
29%
05
21%
5
25%
Compilation Problem
25%
Runtime Problem