M

Mahesh Chandra • 6.28K Points
Tutor III

Q. What should be the execution order, if a class has a method, static block, instance block, and constructor, as shown below?

Code:
    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();  
      }  
    }   
  • (A) Instance block, method, static block, and constructor
  • (B) Method, constructor, instance block, and static block
  • (C) Static block, method, instance block, and constructor
  • (D) Static block, instance block, constructor, and method
  • Correct Answer - Option(D)
  • Views: 140
  • Filed under category JAVA

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics