adplus-dvertising
frame-decoration

Question

What is the output of the below Java program with packages?
//MathClas.java
package package1;
public class MathClass
{
  public static int getRandom()
  {
    //returns a random number from 0 to 999
    return ((int) (Math.random() * 1000)); 
  }
}

//PackageTest3.java
import package1.*;
public class PackageTest3
{
  public static void main(String[] args)
  {
    System.out.print(MathClass.getRandom());
  }
}

a.

No output

b.

Compiler error

c.

484 (some random number)

d.

None

Answer: (c).484 (some random number)

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the below Java program with packages?

Similar Questions

Discover Related MCQs

Q. What are the uses of a Java Package?

Q. Accessing the variables, constants,or methods of a class, imported from a package is subjective to access modifiers like PUBLIC, PRIVATE, PROTECTED and default. State TRUE or FALSE.

Q. Choose a correct statement about using the classes or interfaces or abstract classes inside the packages in our Java program.

Q. Which is the symbol used to separate a super-package and a sub-package at the time of declaring or importing in a Java program?

Q. What are the popular Classes or Interfaces inside a Java Language Pack (java.lang)?

Q. Which is the default Java package that will be auto included (imported) in the classpath while Compiling and Running a Java program?

Q. How does JAVAC or JAVA (JVM) find the packages that will be used inside classes by an import statement?

Q. You can place a comment before the Package Declaration statement in Java. State TRUE or FALSE.

Q. The package declaration statement should be the first statement in a Java file. State TRUE or FALSE.

Q. When importing a Package, theClass isactually importing ____.

Q. Choose a correct statement below about importing packages into a class.

Q. What is the maximum number of levels or depth up to which sub-packages can be defined in Java?

Q. You can use the same name for a Parent package and Child package in Java. State TRUE or FALSE.

Q. Choose correct declaration and importing of packages in Java.

Q. Which is the correct syntax to import a Java package below?

Q. The keyword used to import a package into Java class or Interface is ___.

Q. It is possible to declare a package and import another package within the same Java class file. State TRUE or FALSE.

Q. The name of a package is the name of the ___ in Java.

Q. What is the maximum number of Java Class files that can be kept inside a single Java Package?

Q. The keyword used to declare a Java package is ____.