Skip to main content

MCQ Test-1

MCQ Test Series
Test-1
--------------------------------------------------------------------------------------

1. Which of the following is FALSE about the Singleton Class?
A. It provides the private constructor only.
B. It provides a static factory method to return the instance of the class.
C. It provides a public static reference of the same class type.
D. None of These


2. What will be the output: 
class Continue {
     public static void main(String args[]){
           for(int i=0; i<5; i++) {
                        System.out.print(i + " ");
                        if (i%2 == 0) continue;
                        System.out.print("No Continue ");
                }
          }
 }
A. 0 1 No Continue 2 No Continue3 4
B. 0 1 No Continue 2 3 No Continue 4
C. 0 No Continue 1 2 No Continue 3 4
D. Compilation Error


3. What will be the output?
public class Test{
      public static void main(String args[]){
            int i = 1;
            do{
                      i--;
                }while(i > 2);
            System.out.println(i);
      }
}
A. -1                B. 0                  C. 1                 D. 2


4. Which of the following statement is TRUE about the following method?
 public void test(int a)
{
    int x = 1;
    if(x)
    {
        System.out.println("X");
    }
    else
    {
        System.out.println("Y");
    }
}

A. It will always print X
B. It will always print Y
C. Compilation Error
D. Runtime Error


5. switch(x)
{
    default: 
        System.out.println("Hello");
}
Which two are acceptable types for x?

A. byte and char           B. char and float
C. long and float           D. char and double


6. What is the output of this program?

    class Output {
        public static void main(String args[])
        {   
             int a = 5, b = 10;
             first: {
                second: {
                        third: {
                             if (a ==  b >> 1)     break second;
                          }
                   System.out.println(a);
                }
                System.out.println(b);
             }
        }
    }

A. 5 10                        B. 5 5               C. 5                 D. 10


7. What will be the output of the following program?
    class selection {
        public static void main(String args[])
        {
            int var1 = 5, var2 = 6;
            if ((var2 = 1) == var1)
                System.out.print(var2);
            else
                System.out.print(++var2);
        }
    }
A. 1                 B. 2                  C. 6                 D. 7


8. If an expression contains int, double, float, and long type variables, then whole expression will be promoted into which of these data types?

A. long                         B. int                            C. double                     D. float


9. What will be the Output of the following program?
 
class A{
        public static void main(String args[]){
         int x;
          x = 10;
         if(x == 10){
          int y = 20;
          System.out.print("x and y: "+ x + " " + y);
          y = x*2;
         }
         y = 100;
         System.out.print("x and y: " + x + " " + y);
        }
}
A. 10 20 10 100                      B. 10 20 10 20            
C. 10 20 10 10                        D. Compilation Error



10. Which of the following statement will result in compilation error?
A. boolean b = 4>3 & 5<2;                  B. -43>>>2;
C. boolean b = 0;                                 D. None of These


11. Which of the following is NOT a unary operator?
A. !                  B. &                 C. +                 D. Both B & C


12. If class Y is a subclass of X, Which of the following statement will return true?
                        X x1 = new Y();
A. x1 != null;                                        B. x1 instanceof Y
C. Both A & B                         D. None of These


13. What will be the output of the following code snippet?
           
            ArrayList al = new ArrayList(2);
            al.set(1, "Hello");
            System.out.println(al);

A. [ , Hello]                              B. [Hello]
C. Compilation Error                D. Run-time Error


14. What will be the output of the following code snippet?
    ArrayList al = new ArrayList();
    al.add("A"); al.add("B"); al.add("C");
    ArrayList al2 = new ArrayList();
    al2.add("Hi");
    System.out.println(al2.add(al));

A. [Hi, [A, B, C]]                                 B. [Hi, A, B, C]
C. true                                                  D. Compilation Error


15. Given:
                        String s = "Hello World";
    Which of the following statement will print "World"?
A. System.out.println(s.substring(6, 11));
B. System.out.println(s.substring(6, 10));
C. System.out.println(s.substring(7, 11));
D. System.out.println(s.substring(6, 10));

16. What will be the output of the following code snippet?
            String s = "This is an island";
            System.out.println(s.lastIndexOf("is"));

A. 11               B. 12                C. 2                 D. None of These


17. Which of the following is FALSE about final keyword?
A. A Final class can not be inherited.
B. A final method can not be overloaded.
C. Value of a final variable can not be changed.
D. None of These


18. What will be the output of the following code snippet?
    StringBuilder b = new StringBuilder("Welcome");
    System.out.println(b.delete(3, 5));

A. Welme                     B. Wele            C. Weme                     D. None of These


19. Which of the following statement will delete the the third element of an ArrayList al containing 5 elements?
A. al.delete(3);                         B. al.remove(3);          
C. al.delete(2);                         D. al.remove(2);


20. What will be the output of the following code:
int i= 5, j=2;
for(  ; i-- > ++j ;  )       
    System.out.println(i+””+j);

A. 43               B. 53                C. 34               D. Compilation Error



 


Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. 1. C
    2. B
    3. B
    4. C
    5. A
    6. D
    7. D
    8. C
    9. D
    10. C
    11. B
    12. C
    13. D
    14. C
    15. A
    16. A
    17. B
    18. A
    19. D
    20. A

    ReplyDelete
    Replies
    1. in the 7th question the answer will b.2 instead of D.7
      because in the if statement var2 is assigned with the value 1 and at the
      print statement you have incremented its value so the answer will be 2

      Delete

Post a Comment

Popular posts from this blog

Practice Set

1. Write a program to create a class Voter which contains attributes name, date_of_birth and voter_id and voter has a Voter_Card. Provide appropriate constructor to initialize all the attributes of the Voter but voter id must be assigned automatically only when the age of the voter is greater than or equal to 18 years. VoterCard is a nested class with attributes voter_id and Voter_name. Make sure that voter card is created only when user is a valid voter and if it is already created then must not be assigned the new voter id. 2. Write a program to define two interfaces UGC and AICTE both having a default method int getAdmission() to take the admission and an abstract method String payFee(). getAdmission() in UGC must ask the percentage in qualifying exam and if the percentage >= 60 then generate the registration number and return. getAdmission() is AICTE must ask the user to join the counseling after 5 days and display the date of counseling and return the counseling token numb...

Practice Set: Unit-4

                                                                                                                Practice Set: Unit 4 1. What are the uses of super keyword in Java? Explain with a suitable example. 2. What are the various uses of final keyword in java? An abstract method can not be declared final. Why? 3. Differentiate between Abstract class and Interface. What do you mean by Functional interface and Lambda Expression?  ...

ETE Practice Set-1

                                                                 Mock Test-1 -----------------------------------------------------------------------------------------------------------------------------   1 (a) Write a program that reads 10 integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0.                                                         ...