I have worked with PHP for 6 years now and am certified in it, but lately I have decided that I should learn Java, as I worked a lot with the Zend framework, which is inspired by Java, but now I have what is, perhaps, a stupid problem with Java.
In PHP I would do this:
class Cool
{
protected $_name;
function __construct($name)
{
$this->_name = $name;
}
function showName()
{
echo "{$this->_name} is a cool guy";
}
}
class Bad extends Cool
{
function showName()
{
echo "{$this->_name} is a bad guy";
}
}
$bad = new Bad("jhon");
// prints jhon is a bad guy
Since Java doesn't inherit constructors, what would be the best way to do something like this in Java? Will I have to think of a different type of patterns to solve this kind of thing?
I appreciate the help since I'm really new to Java and since I use this kind of thing a lot I'd like to know if there's any cool way to do it in Java. I need to use it on a new project I'm getting assigned to.