You need to pass commonTitle
as a new extra method parameter to commonFormatting
. Your commonTitle
variables are local variables, which means they are only visible inside the method they are declared in.
Polymorphism and encapsulation have nothing to do with why the code does not compile. Indeed, you are not using polymorphism, which might be a good way to solve this problem.