In simple words:
- the left side before "=" means what the object may do,
- the right side after "=" means how an object will do.
So:
public class Parent {
private String someVar = "Parent variable";
public void someMethod(){
System.out.println(someVar);
}
}
public class Child extends Parent{
protected String someVar = "Child variable";
public void someMethod() {
System.out.println(someVar);
}
}
public class Main {
public static void main(String[] args) {
Parent p = new Child();
p.someMethod();
Parent p2 = new Parent();
p2.someMethod();
}
}
out:
Child variable
Parent variable
//Hope it helps
//This is the child class
public class child
{
public classCall()
{
String str = "I am the child class accessed from parent class!!!";
}
}
//this the parent class
class parent
{
public static void main(String args[])
{
child obj = new child(); //objext of child class is created
System.out.println(obj.classCall()); //'classCall method is called from child class
}
}