{
protected int sides;
public Shape()
{
sides = 3;
}
public int getSides()
{
return sides;
}
public printSides()
{
System.out.println("This object has " + sides + " sides." );
}
}
public class Square extends Shape
{
public Square(int nSides)
{
sides = nSides; // dont need to call super class constructor due to protected type of variable.
}
}
class ProtectedVariableDemo
{
public static void main(String args[])
{
Square sObj = new Square(10);
sObj.printSides();
}
}
Output
This object has 10 sides.