public class Test{
public static void main(String args[]){
System.out.println( Math.floor( Math.random( ) ) ) ;
}
}Select an option to see the answer and solution.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
140
Questions
3/7
Page
Pick an option on a question to see the right answer and solution.
public class Test{
public static void main(String args[]){
System.out.println( Math.floor( Math.random( ) ) ) ;
}
}Select an option to see the answer and solution.
class Num {
Num(double x ){
System.out.println( x ) ;
}
}
public class Test extends Num {
public static void main(String[] args){
Num num = new Num( 2 ) ;
}
}Select an option to see the answer and solution.
class A{
public static void method(int i){
System.out.print("Method 1");
}
public static int method(String str){
System.out.print("Method 2");
return 0;
}
}
public class Test{
public static void main(String args[]){
A.method(5);
}
}Select an option to see the answer and solution.
class Test{
public int display(int x, int y){
return ("The sum of x and y is " + x + y);
}
public static void main(String args[]){
Test test = new Test();
System.out.println(test.display(4,5));
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
class Person{
public int number;
}
public class Test{
public void doIt(int i , Person p){
i = 5;
p.number = 8;
}
public static void main(String args[]){
int x = 0;
Person p = new Person();
new Test().doIt(x, p);
System.out.println(x + " " + p.number);
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
public class Test { }Select an option to see the answer and solution.
class MyClass{
MyClass(){
System.out.print("one");
}
public void myMethod(){
this();
System.out.print("two");
}
}
public class TestClass{
public static void main(String args[]){
MyClass obj = new MyClass();
obj.myMethod();
}
}Select an option to see the answer and solution.
public class Test{
public static void main(String args[]){
MyClass obj = new MyClass();
obj.val = 1;
obj.call(obj);
System.out.println(obj.val);
}
}
class MyClass{
public int val;
public void call(MyClass ref){
ref.val++;
}
}Select an option to see the answer and solution.
class MyClass{
int i;
int j;
public MyClass(int i, int j){
this.i = i;
this.j = j;
}
public void call(){
System.out.print("One");
}
}
public class Test{
public static void main(String args[]){
MyClass m = new MyClass(); //line 1
m.call(); //line 2
}
}Select an option to see the answer and solution.
public class MyClass{ }Select an option to see the answer and solution.
public class A{
int add(int i, int j){
return i+j;
}
}
public class B extends A{
public static void main(String argv[]){
short s = 9;
System.out.println(add(s,6));
}
}Select an option to see the answer and solution.
public class Test{
public static void main(String[] args){
String value = "abc";
changeValue(value);
System.out.println(value);
}
public static void changeValue(String a){
a = "xyz";
}
}Select an option to see the answer and solution.
public class Test{
public static void printValue(int i, int j, int k){
System.out.println("int");
}
public static void printValue(byte...b){
System.out.println("long");
}
public static void main(String... args){
byte b = 9;
printValue(b,b,b);
}
}Select an option to see the answer and solution.
class A{
A(String s){}
A(){}
}
class B extends A{
B(){}
B(String s){
super(s);
}
void test(){
// insert code here
}
}Select an option to see the answer and solution.
class A{
public A(){
System.out.println("A");
}
public A(int i){
this();
System.out.println(i);
}
}
class B extends A{
public B(){
System.out.println("B");
}
public B(int i){
this();
System.out.println(i+3);
}
}
public class Test{
public static void main (String[] args){
new B(5);
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.