Question: In the following code, the classes Box, Pen, and Main are in the same package. Can the Main class be compiled? class Box {

 In the following code, the classes Box, Pen, and Main are in  

In the following code, the classes Box, Pen, and Main are in the same package. Can the Main class be compiled? class Box { protected void math() { } } class Pen extends Box { } class Main { public void p() { Pen p = new Pen(); p.math(); }

Step by Step Solution

3.42 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

No the Main class cannot be compiled The issue lies in the visibility of the method ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!