SCJP Module-1 Question-16

The given program tests your underspending of packages in java and also checks that how to import classes in Java.

 
 

Share on Google+Share on Google+

SCJP Module-1 Question-16

Ads

The given program tests your underspending of packages in java and also checks that how to import classes in Java.

Given a sample code:

1 package roseindia;

2 public class ClassA {

3 public static void doSomething() {
4 System.out.println("do something");
}}

5 // Place the statement here

6 public class ClassB {
7 public static void main(String args[]) {
8 ClassA.doSomething();
}}

What statement you place at line number 5 for successful compilation and execution of above code?

(1) import roseindia.*;
(2) import roseindia.ClassA;
(3) import roseindia.ClassA.doSomething.*;
(4) import ClassA;

Answer:

(1) or (2)

Explanation:

Place statement (1) or (2) both allow the ClassA method to be called from ClassB.

Advertisements

Posted on: July 8, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles