Home Tutorial Java Scjp Part1 SCJP Module-1 Question-16

 
 

SCJP Module-1 Question-16
Posted on: July 8, 2010 at 12:00 AM
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.

Related Tags for SCJP Module-1 Question-16:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.