Reputation: 489
I have a outer class called Packet with 3 instance vars, myint1 to myint3.
I also want to create a class called Subpacket, which should point to myint1 and myint2.
Should i make Subpacket as an inner class of Packet?
So for eg, if Packet has myint1=1, myint2=2 and myint3=3, then if a class Foo refers to the Subpacket object, it would access myint1 and myint2.
I will pass Packet objects to some methods and Subpacket objects to some other methods.
So the question is is it a good idea to make Subpacket an inner class of Packet?
Upvotes: 0
Views: 113
Reputation: 36304
You need inheritance.. SubPacket
should extend Packet
.
Where,
class Packet {
protected int myInt1; // accessible in subclass
protected int myInt2;
private int myInt3; // not accessible by child class
}
class SubPacket extends Packet {
}
Upvotes: 3