Java Data Types, Variables and Arrays Mcqs

Our collections of Multiple choice questions and answers focuses on study of Java Data Types, Variables and Arrays . These questions are chosen from a collection of most authoritative and best reference books on Java Data Types, Variables and Arrays. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate Data Types, Variables and Arrays comprehensively.

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

Sorted in the order of declaration of Enums

Sorted in alphabetical order of Enums

Sorted based on order() method

Sorted in descending order of names of Enums

2.
What is the output of below code snippet?

class A
{
 
}
 
enum Enums extends A
{
    ABC, BCD, CDE, DEF;
}

Runtime Error

Compilation Error

It runs successfully

EnumNotDefined Exception

3.
What is the output of below code snippet?

enum Levels 
{
    private TOP,
 
    public MEDIUM,
 
    protected BOTTOM;
}

Runtime Error

EnumNotDefined Exception

It runs successfully

Compilation Error

4.
What is the output of below code snippet?

enum Enums
{
    A, B, C;
 
    private Enums()
    {
        System.out.println(10);
    }
}
 
public class MainClass
{
    public static void main(String[] args)
    {
        Enum en = Enums.B;
    }
}

10 10 10

Compilation Error

10 10

Runtime Exception

9.
What is the output of below code snippet?

enum Enums
{
    A, B, C;
 
    private Enums()
    {
        System.out.println(10);
    }
}
 
public class MainClass
{
    public static void main(String[] args)
    {
        Enum en = Enums.B;
    }
}

0.009999999999999998 0.01

0.01 0.009999999999999998

0.01 0.01

0.009999999999999998 0.009999999999999998

11.
What is the limitation of toString() method of BigDecimal?

There is no limitation

ToString returns null

ToString returns the number in expanded form

ToString uses scientific notation

14.
What is BigDecimal.ONE?

Wrong statement

Custom defined statement

Static variable with value 1 on scale 10

Static variable with value 1 on scale 0

16.
What is the output of below code snippet?

public class AddDemo 
{
 public static void main(String args[]) 
        {
  BigDecimal b = new BigDecimal("23.43");
  BigDecimal br = new BigDecimal("24");
  BigDecimal bres = b.add(new BigDecimal("450.23"));
  System.out.println("Add: "+bres);
 
  MathContext mc = new MathContext(2, RoundingMode.DOWN);
  BigDecimal bdecMath = b.add(new BigDecimal("450.23"), mc);
  System.out.println("Add using MathContext: "+bdecMath);
 }
}

Compilation failure

Add: 684.66 Add using MathContext: 6.8E+2

Runtime exception

Add 6.8E+2 Add using MathContext: 684.66

error: You are not allowed to do so.....
0Shares
0
Scroll to Top