Answer by midor for Java this in parent and child not working as expected
The way you would set the s-member in the parent-portion of a child-class, would be to offer a protected constructor (it could, of course, also be public): protected Parent(String s) { this.s = s; }...
View ArticleAnswer by Nadim Baraky for Java this in parent and child not working as expected
You should create a getter method i.e. getS() in the Child class to retrieve "Child" when you call child.getS() in your main method. In this way, you override the getS() method that was inherited from...
View ArticleAnswer by Prasad Kharkar for Java this in parent and child not working as...
Your getS() methods from parent class is inherited in Child class and hence it is available for Child object. Overriding is only for methods and not for instance variables. So even if you define a new...
View ArticleJava this in parent and child not working as expected
I'm misunderstanding something really basic with inheritance. I have a parent class: public class Parent { String s = "Parent"; Parent () {} String getS() { return this.s; } } and a child class:...
View Article