What will be the output of the following Java program?

import java.lang.reflect.*;
    class Additional_packages
    {	 
         public static void main(String args[])
         {
         try
             {
             Class c = Class.forName("java.awt.Dimension");
         Constructor constructors[] = c.getConstructors();
         for (int i = 0; i < constructors.length; i++)
             System.out.println(constructors[i]);
         }
         catch (Exception e)
             {
                   System.out.print("Exception");
             }
        }
    }

a) Program prints all the constructors of ‘java.awt.Dimension’ package
b) Program prints all the possible constructors of class ‘Class’
c) Program prints “Exception”
d) Runtime Error

1 thought on “What will be the output of the following Java program?”

  1. a
    Explanation: None.
    Output:
    $ javac Additional_packages.java
    $ java Additional_packages
    public java.awt.Dimension(java.awt.Dimension)
    public java.awt.Dimension()
    public java.awt.Dimension(int,int)

Leave a Comment