Skip to main content

MTE Challenge-1

1. What will be the output of the following Program?

class A {}
class B extends A
{
   public void show()
    {
        System.out.println("Bye");
    }
   public static void main(String [] rk)
    {
        A a1 = new B();
        a1.show();   
    }
}

A. Bye            B. Compilation Error   
C. Runtime Error    D. None of These



2. What will be the output of the following Program?

class A
{
    private A(){}
}
class B extends A
{
   B()
    {
    System.out.println("Bye");
    }
   public static void main(String [] rk)
    {
        A a1 = new B();   
    }
}

A. Bye            B. Compilation Error   
C. Runtime Error    D. None of These


3. What will be the output of the following Program?

class A
  {
   public void show()
    {
        System.out.println("Hi");
    }
  }
class B extends A
{
   public void show()
    {
        System.out.println("Bye");
    }
   public static void main(String [] rk)
    {
        A a1 = new B();
        a1.show();   
    }
}

A. Bye            B. Compilation Error   
C. Runtime Error    D. Hi




4. What will be the output of the following Program?

class A
{
   A(int x) {    this("Hi");
        System.out.print("L");
        }
   private A(String x) {   
        System.out.print("P");
        }
}

class B extends A
{
    private B(){    super(1);
            System.out.print("U");
        }
   public static void main(String [] rk)
    {
        B b1 = new B();   
    }
}

A. PLU        B. LPU       
C. ULP        D. Compilation Error




5. What will be the output of the following code snippet?

class Test{
        public void display(int x, double y){
                System.out.println(x+y);
        }
        public double display(int a, double b){
                return (a*b);
        }
        public static void main(String args[]){
                Test t = new Test();
                t.display(4, 5.0);
           }
}

A. 9            B. 36       
C. Compilation Error    D. None of These




6. What will be the output of the following code snippet?

class A
{
   public static void demo()
    {
        System.out.println("Hi");
    }
}
class B extends A
{
   public static void demo()
    {
        System.out.println("Hello");
    }
   public static void main(String [] rk)
    {
        A a1 = new B();
        a1.demo();
    }
}

A. Hi            B. Hello
C. Compilation Error    D. Runtime Error



       
7. What will be the output of the following code snippet?

class A
{
   public void demo()
    {
        System.out.println("Hi");
    }
}
class B extends A
{
   public void demo()
    {
        System.out.println("Hello");
    }
   public static void main(String [] rk)
    {
        A a1 = new B();
        a1.demo();
    }
}

A. Hi            B. Hello
C. Compilation Error    D. Runtime Error




8. What will be the output of the folowing code snippet?

public class Test{
        public static void main(String [] rk){
                int i;
                for(i = 1; i < 6; i++)
        {
                        if(i > 3) continue;
                }
                System.out.println(i);
        }
}

A. 4        B. 5        C. 6        D. None of

These



9. What will be the output of the folowing code snippet?

public class Test{
        public static void main(String [] rk){
                int i;
                for(i = 1; i < 6; i++)
        {
                        if(i > 3) break;
                }
                System.out.println(i);
        }
}

A. 4        B. 5        C. 6        D. None of

These



10. What will be the output?

class Demo{
        public static void main(String[] rk){
                int [] a = new int[0];
                System.out.print(a.length);
        }
}

A. 0    B. 10    C. Compilation Error    D. None of These

11. What will be the output?

class Demo{
        public static void main(String[] rk){
                int a [10];
                System.out.print(a.length);
        }
}

A. 0    B. 10    C. Compilation Error    D. None of These




12. What will be the output?
public class StringDemo{
        public static void main(String [] rk){
            String s1 = new String("Hi");
        String s2 = new String("Bye");
        System.out.println(s1 = s2);
    }
}

A. Hi            B. Bye       
C. Compilation Error    D. None




13. What will be the output?
public class StringDemo{
        public static void main(String [] rk){
            String s1 = new String("Hi");
        String s2 = new String("Bye");
        System.out.println(s1 == s2);
    }
}

A. true            B. false   
C. Compilation Error    D. None




14. What will be the output?

class TestString{
        public static void main(String args[]){
                String s1 = new String("Hello");
                String s2 = new String(s1);
                System.out.println(s1 == s2);
        }
}

A. true            B. false   
C. Compilation Error    D. None



15. What will be the output?

class TestString{
        public static void main(String args[]){
                String s1 = new String("Hello");
                String s2 = new String(s1);
                System.out.println(s1.equals(s2));
        }
}

A. true            B. false   
C. Compilation Error    D. None



16. What will be the output?

StringBuilder b = new StringBuilder('A');
System.out.println(b.capacity() + ""+ b.length());

A.810        B. 811        C. 171        D. 650



17. What will be the output?

ArrayList a = new ArrayList();
a.add("A");     a.add("B");   
a.set(1, "X");     a.add(2, "C");
System.out.println(a);

A. [A, X, B, C]        B.[A, X, B]       
C. [A, X, C]        D. Runtime Error


   


18. Which of the following is an invalid array declaration?
A. int ... arr;
B. char ch [] = {A, B, C, D, E};
C. boolean [] b = {false, true, true};
D. Object ob [] = new Object[10];





19. What will be the output of the following statement?

System.out.println( 3>4 || 4>3 ? false : true);

A. true            B. false        
C. falsetruefalse    D. Compilation Error



20. The following class is saved in a file named as

Hello.java. Which of the following is TRUE about it?
public class A{}
A. It can be compiled using command javac A.java
B. It will be compiled using command javac A.java
C. It must be saved in a file named as A.java, otherwise it

will not compile.
D. None of These



21. Which of the following is CORRECT char variable

declaration?

A. char c = (int)65.1;
B. char c = a;
C. char c = '11';
D. None of These;



22. What will be the output of the following code snippet?
   if(!true) System.out.print("Hi ");
      if(true) System.out.print("Hello ");
      else("Bye");

A. Hi Bye   B. Hello   C. Bye    D. Compilation Error        



23. We can use these features of an abstract class even

without inheriting it.
A. all the public static and non static members
B. all the public static members
C. all the public non static members
D. none of the above


24. Singleton Design pattern is used ___.
A. To ensure that the inheritance of the class is prevented.
B. To ensure that only one instance of the class can be

created.
C. To ensure that all the abstract methods are implemented

by the subclass.
D. Both A and B



25. Can an abstract parent class have non-abstract children?
A. No--an abstract parent must have only abstract children.
B. No--an abstract parent must have no children at all.
C. Yes--all children of an abstract parent must be non-

abstract.
D. Yes--an abstract parent can have both abstract and non-

abstract children.


26. Which of the following is FALSE about final keyword in

Java?

A. It is used to prevent the inheritance of a class.
B. It is used to declare the constant in Java.
C. Local variables can not be declared final.
D. Abstract class can not be declared final.



27. Which of the following is FALSE about Abstract class?
A. Abstract class can not inherit another abstract class.
B. Abstract class can have constructors.
C. Abstract class can not be declared private.
D. Abstract class can contain non-abstract methods.




28. What will be the output of the following code?
class Test

   int x=10;
   Test(int a)
    {
    System.out.print(x);
    x=a;
    }
   public static void main(String [] arg)
    {
        new Test(5);
    }   
}

A. 0    B. 5     C. 10    D. Compilation Error



29. 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");
    al.add(2, al2)
    System.out.println(al);

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




30. Which of the following is INCORRECT header for the main

method in java?

A. public static void main(String [] arg)
B. static public void main(String arg [])
C. public static void main(String...arg)
D. None of These








Comments

  1. Good Post! Thank you so much for sharing the post, it was so good to read and useful to improve
    Java Training in Electronic City

    ReplyDelete

Post a Comment

Popular posts from this blog

Practice MCQs

  1. What will be the Output of the following code? class X{                  static int x = 1;                        static class Y {                              static int y = x++;                                static class Z                                                                       {                                                                                         static int z = ++y;                                                                        }                                               }                }   class MainClass{     public static void main(String[] rk)    {                             System.out.print(X.x);                                             System.out.print(X.Y.y);                             System.out.print(X.Y.Z.z);         } } A. 113 B. 123 C. 111 D. None of These Ans: A 2.  Which of the following statement is TRUE about t he following code? public class Outer  {    private i

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

Mock Test - 1

1. Which of the following is a byte stream class? A. ObjectInputStream B. Writer C. PrintWriter D. Scanner Ans: A 2. Which exception is thrown by read() method in InputStream class? A. IOException B. InterruptedException C. FileNotFoundException D. None of These Ans: A 3. Which of the following class is subclass of FilterInputStream? A. InputStream B. ObjectOutputStream C. FileInputStream D. BufferedInputStream  Ans: D 4. Which of these class contains the print() and println() methods? A. System B. out C. PrintStream D. BUfferedOutputStream Ans: C 5. Which of these is a method to clear all the data present in output buffer without terminating the stream? A. clear() B. fflush() C. flush() D. close() Ans: C 6. Which of these classes defined in java.io and used for file-handling are abstract? (i) InputStream        (ii) PrintStream    (iii) Reader        (iv) FileInputStream A. Only i     B. i and ii    C. Only iii    D. i and iii Ans: D 7. What is the output of this program? class MyE