Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/how-to-access-a-class-from-another-package-in-java
Question 35 / 297:  You have two packages, trunk1 and trunk2 where class Sheet declared in trunk1

and class Container declared in trunk2, the following code contains a compilation error, where could it be?

package trunk1;

public class Sheet {

public static int pageNumber = 99; // line 1

Sheet() {} // line 2

}

package trunk2;

import trunk1.Sheet;

public class Container {

public static void main(String... args) { //line 1

System.out.print(Sheet.pageNumber); //line 2

Sheet sheet = new Sheet(); //line 3

}

}

A  In package trunk1 at line 2, constructor Sheet must be marked public like its class
B  In package trunk2 at line 1, invalid string argument for method main()
C  In package trunk2 at line 2, invalid access to member pageNumber
D  In package trunk2 at line 3, invalid call to constructor Sheet()
<< First < Previous Next > Last >>
Explanation:

The Sheet constructor has a package access scope, so it cannot be called outside its package

Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Jemekia Weeden
Start Quiz
Madison Christian
Start Test
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>