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

 
 

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

Advertisement

Related Tags for SCJP Module-1 Question-16:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 8, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com