Logo

Java Questions Set 172:

Quiz Mode

The map is an interface

1
2

Solution:

javap java._____.String

1
2
3

Solution:

Sorted map extends

1
2
3
4

Solution:

All methods must be implemented in an interface?

1
2

Solution:

What are the correct statements about Java packages?

1
2
3
4
5

Solution:

What is the correct way to implement an interface?

For example, ‘Operation’ interface implements ‘Add’ class.

1
2
3
4

Solution:

Predict the output of the following Java code:

//Predict the output

import java.util.Scanner;

public class MyClass

{

public static void main(String args[])

{

String str = "How to work java in java compiler";

String Str1 = str.replaceAll("java", "c");

System.out.println(Str1);

}

}

1
2
3
4

Solution:

 class method 

    {

        private int i;

     static int j;

        void add(int a , int b)

        {

            i =++j + ++b;

            j =++i + b++;

        }

    }    

    class output 

    {

        public static void main(String args[])

        {

            method obj1 = new method();

            method obj2 = new method();   

            int a = 5;

            obj1.add(++a, ++a + 1);

            obj2.add(6, a);

            System.out.println(obj1.i+" "+obj2.j);     

        }

   }

1
2
3
4

Solution:

What will be the output of the following Java code?

class Abekus {

public static void main(String args[]) {

String str1 = new String("Hi Java Learner");

String str2 = new String("Hi Java Learner");

String str3 = "Hi Java Learner";

String str4 = "Hi Java Learner";

int a = 0, b = 0, c = 0;

if (str3 == str4) a = 1;

else a = 2;

if (str1.equals(str3)) b = 1;

else b = 2;

if (str1 == str4) c = 1;

else c = 2;

System.out.println("a= " + a + " b= " + b + " c= " + c);

}

}

1
2
3
4

Solution:

Predict the output of the following Java code:

class Hashcode {

public static void main(String[] args) {

String o1 = new String("Abekus");

String o2 = new String("Abekus");

if(o1.hashCode() == o2.hashCode())

System.out.println("Hashcode of object1 is equal to object2.");

if(o1 == o2)

System.out.println("Memory address of object1 is same as object2.");

if(o1.equals(o2))

System.out.println("Value of object1 is equal to object2.");

}

}

1
2
3
4

Solution: