JAVA QUIZ 12

22
Created on By Sirjana GhimireAcharya

JAVA QUIZ 12

1 / 10

1.Which of these is sorted by default

2 / 10

2. Which of these maintains insertion order?

3 / 10

3. What is the output of the following code?

public class Laptop
{
String brand;
int hardDisk;

Laptop(String brand, int hardDisk)
{
this.brand = brand;
this.hardDisk = hardDisk;
}
public static void main(String[] args)
{
Laptop laptop1 = new Laptop("Dell", 500);
Laptop laptop2 = new Laptop("HP", 300);
laptop1 = laptop2;
Laptop laptop3 = laptop1;
System.out.print(laptop3.brand + ", ");
System.out.print(laptop1.hardDisk);
}
}

4 / 10

4. What is the output of the following program?

public class Laptop
{

public static void main(String[] args){

int i = 10;
int j = 12;
i+=++j;
System.out.println(i);

}
}

5 / 10

5. What will happen when you compile and run the following code?

public class Test{

public static void main(String[] args){

boolean b1 = true;
boolean b2 = true;

if(b1 == b2){
System.out.print("==");
}

if(b1.equals(b2)){
System.out.print("equals");
}
}
}

6 / 10

6. What will happen when you compile and run the following code?

public class Test{

static String name = "Test";

public Test(){
name = "TestObject";
}

public static void main(String[] args){
System.out.println("Name is " + name);
}
}

7 / 10

7. What will happen when you compile and run the following code?

public class Test{

public static void main(String[] args){

MyMathClass m = new MyMathClass();

int i=10, j=15;
m.sum(i, j);

float f1=3.4f, f2=9.23f;
m.sum(f1, f2);

char c1='a', c2='b';
m.sum(c1, c2);
}
}

class MyMathClass{

public void sum(int i1, int i2){
System.out.print(":int");
}

public void sum(String str1, String str2){
System.out.print(":String");
}

public void sum(double d1, double d2){
System.out.print(":double");
}
}

8 / 10

8. Will this code compile without error?

public class Test{
public native int getArea(int w, int h);
}

9 / 10

9.Output of follwoing Java program

class Main {
public static void main(String args[]){
final int i;
i = 20;
System.out.println(i);
}
}

10 / 10

10.Output of following Java program?

class Test {
public static void swap(Integer i, Integer j) {
Integer temp = new Integer(i);
i = j;
j = temp;
}
public static void main(String[] args) {
Integer i = new Integer(10);
Integer j = new Integer(20);
swap(i, j);
System.out.println("i = " + i + ", j = " + j);
}
}

Your score is

The average score is 49%

0%