Failed in created an object of protected inner class

B

Bruce Sam

I have created an interface Car with at least one method price(),
in its own package sam.bruce.c01. And then created a class in a
separate package sam.bruce.c02. Add a protected inner class NewCar that
implements the interface Car. In a third package sam.bruce.c03, inherit
from my class and, inside a method, return an object of the protected
inner class, upcasting to the interface during the return.Above is all
I want to do.My java code is list below:

Code:
/* ********************* */
package sam.bruce.c01;


public interface Car {
int price();
}
/* ********************* */
package sam.bruce.c02;

import sam.bruce.c01;


public class MyCar1 {
private int m_price = 10;
protected class NewCar implements Car {
public int price() {
return m_price;
}
}
}
/* ********************* */
package sam.bruce.c03;

import sam.bruce.c02;

public class MyCar2 extends MyCar1 {
public void getCar() {
MyCar1 p = new MyCar1();
MyCar1.NewCar pnew = p.new MyCar1.NewCar(); //error
}

public static void main(String[] args) { }
}
/* ****************** */

I failed in created an object of protected inner class.What is
the correct method to do this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top