Home » JAVA Programming » Packages » Question
  1. What is the output of this program?
    package pack;
    class dis
    {
    int p;
    void output()
    {
    if (p > 1)
    System.out.print(p + " ");
    }
    }

    public class packages_Example
    {
    public static void main(String args[])
    {
    dis[] array=new dis[5];
    for(int k=0; k<5; k++)
    array[k]=new dis();
    array[0].p = 5;
    array[1].p = 7;
    array[2].p = 9;
    for (int k = 0; k < 5; ++k)
    array[k].output();
    }
    }

    Note : packages_Example.class file is in directory pack;
    1. 7 9
    2. 5 7 9
    3. 7 5 9
    4. 9 7 5
    5. None of these
Correct Option: B

5 7 9



Your comments will be displayed only after manual approval.