Vidyalelo
Java Programming · all questions

Data Types and Variables
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

127

Questions

5/7

Page

Pick an option on a question to see the right answer and solution.

If we try to add Enum constants to a TreeSet, what sorting order will it use?

Select an option to see the answer and solution.

What is the base of BigDecimal data type?

Select an option to see the answer and solution.

What will be the output of the following Java statement?
class output {
        public static void main(String args[]) 
        {
            double a, b,c;
            a = 3.0/0;
            b = 0/4.0;
            c=0/0.0;
 
	    System.out.println(a);
            System.out.println(b);
            System.out.println(c);
        } 
    }

Select an option to see the answer and solution.

What will be the output of the following Java code?
class booloperators {
    public static void main(String args[]) 
    {
        boolean var1 = true;
  boolean var2 = false;
  System.out.println((var1 & var2));
    } 
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
class conversion 
{
    public static void main(String args[]) 
    {
        double a = 295.04;
        int  b = 300;
        byte c = (byte) a;
        byte d = (byte) b;
        System.out.println(c + " "  + d);
    } 
}

Select an option to see the answer and solution.

An expression involving byte, int, and literal numbers is promoted to which of these?

Select an option to see the answer and solution.

Literal can be of which of these data types?

Select an option to see the answer and solution.

What is the numerical range of a char data type in Java?

Select an option to see the answer and solution.

How is Date stored in database?

Select an option to see the answer and solution.

Which method returns the elements of Enum class?

Select an option to see the answer and solution.

What will be the output of the following Java code?
class char_increment 
{
    public static void main(String args[]) 
    {
        char c1 = 'D';
        char c2 = 84;
        c2++;
        c1++;
        System.out.println(c1 + " "  + c2);
    } 
}

Select an option to see the answer and solution.

Which one is a valid declaration of a boolean?

Select an option to see the answer and solution.

Which of the following are legal lines of Java code?
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;

Select an option to see the answer and solution.

BigDecimal is a part of which package?

Select an option to see the answer and solution.

What is the range of byte data type in Java?

Select an option to see the answer and solution.

Which of these is an incorrect string literal?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class evaluate 
{
    public static void main(String args[]) 
    {
        int a[] = {1,2,3,4,5};
  int d[] = a;
  int sum = 0;
  for (int j = 0; j < 3; ++j)
            sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);
  System.out.println(sum);
    } 
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
class area {
    public static void main(String args[]) 
    {    
         double r, pi, a;
         r = 9.8;
         pi = 3.14;
         a = pi * r * r;
         System.out.println(a);
    } 
}

Select an option to see the answer and solution.

What is the replacement of joda time library in java 8?

Select an option to see the answer and solution.

How to get difference between two dates?

Select an option to see the answer and solution.