I have the following classes
class A{
private String name;
private int value;
public A(String n, int v){
name = n;
value = v;
}
public void print(){
System.out.println(name + " " + value);
}
}
class B extends A{
public B(String n, int v){
super(n,v);
}
}
When i say B b = new B("new object", 1);
it created an object of type B with name = new object and value = 1. and printed the same on calling print() method. But though it has those values in it, i cant access them through B's methods. Is it the limitation of encapsulation or inheritance.
Because the same situation is there in front of me where i need to extend a third party class and the properties in this class which are private but are needed in the extending class, and there are no setters and getters for the private members. So what do i have to do?