Gadgets 4 Students Career Guide Free Tutorials  Go to Your University  Placement Preparation 
1 like 0 dislike
97.1k views
in Technical Questions by Goeduhub's Expert (5.8k points)
MCQ's Questions on Java along with answers

1 Answer

1 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited by
 
Best answer

Java MCQ's Questions Set 3

Q.1. What will be the output of the following program?

public class First_C {

public void myMethod()

 { System.out.println("Method");  }    

{

  System.out.println(" Instance Block");  

 }  

public void First_C()  

{  System.out.println("Constructor ");   }  

 static {  

        System.out.println("static block");   }  

    public static void main(String[] args) {  

    First_C c = new First_C();  

    c.First_C();  

    c.myMethod();  

  }  

}   

  1. Instance block, method, static block, and constructor
  2. Method, constructor, instance block, and static block
  3. Static block, method, instance block, and constructor
  4. Static block, instance block, constructor, and method

Answer:- (4)


Q.2. What will be the output of the following Java code?

class bool_operator 

{

   public static void main(String args[]) 

   {    

        boolean a = true;

        boolean b = !true;

        boolean c = a | b;

        boolean d = a & b;

        boolean e = d ? b : c;

        System.out.println(d + " " + e);

    }

 }

  1. false false
  2. true ture
  3. true false
  4. false true

Answer:- (4)


Q.3. What will be the output of the following program?

public class MyFirst {

      public static void main(String[] args) { 

         MyFirst obj = new MyFirst(n);

 }

 static int a = 10; 

 static int n; 

 int b = 5; 

 int c; 

 public MyFirst(int m) {  

       System.out.println(a + ", " + b + ", " + c + ", " + n + ", " + m);  

   } 

// Instance Block 

  { 

     b = 30; 

     n = 20; 

  } 

// Static Block  

  static  

          a = 60; 

     } 

 }

  1. 10, 5, 0, 20, 0
  2. 10, 30, 20
  3. 60, 5, 0, 20
  4. 60, 30, 0, 20, 0

Answer:- (4)


Q.4. Which of the following is/are true about constructors in Java?

  1. Constructor name should be same as class name.
  2. If you don't define a constructor for a class, a default parameterless constructor is automatically created by the compiler.
  3. The default constructor calls super() and initializes all  instance variables to default value like 0, null.
  4. If we want to parent class constructor, it must be called in first line of constructor.

(A). 1

(B). 1, 2

(C). 1,2,4

(D). 1,2,3 and 4

Answer:- (D)


Q.5. Predict the output of following Java program

class Test {

  int i;

}

class Main {

  public static void main(String args[]) {

      Test t = new Test();

      System.out.println(t.i);

   }

}

  1. Garbage value
  2. 0
  3. Compile Error
  4. Runtime Error

Answer:- (2)


Q.6. Predict the output of the following program.

class First

{

    void display()

    {

        System.out.println("Inside First");

    }

class Second extends First

    void display()

    {

        System.out.println("Inside Second");

    }

class Test

{

    public static void main(String[] args)

    {

        First obj1 =  new First();

        Second obj2 =  new Second();

        First ref;

        ref = obj1;

        ref.display();

        ref = obj2;

        ref.display();

    }

}


1. Compilation Error

2. Inside First

    Inside Second

3. Inside First

    Inside First

4. Runtime Error

Answer:- (2)


Q.7.  Which method of DataInputStream class reads a line from the file and returns it as a string?

  1. WriteInt()
  2. readLine()
  3. readInt()
  4. writeDouble()

Answer:- (2)


Q.8. Which state is the thread still alive, but is currently not eligible to run?

  1. Non-Runnable
  2. Terminated
  3. Runnable
  4. Running

Answer:- (1)


Q.9. Nested interface must be public if it is declared outside the interface but it cannot have any access modifier if declared within the class.

  1. True
  2. False

Answer:- (2)


Q.10.  In Method overriding a subclass in a different package can only override the non-final methods declared public or protected

  1. True
  2. False

Answer:- (1)


For Java Interview Questions Click here


For more Technical MCQ's and Interview Questions Click here


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

1 like 0 dislike
2 answers 30.6k views
1 like 0 dislike
2 answers 86.0k views
1 like 0 dislike
2 answers 19.2k views
1 like 0 dislike
2 answers 157k views
1 like 0 dislike
2 answers 20.6k views

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory
...