Hi
I am not able to understand the behaviour of below mentioned codes
======================================
Code A -
class Parent {
String message = "parent";
void say() {
System.out.println(message);
}
}
class Child extends Parent {
String message = "child";
}
public class
Test {
public static void main(String[] args) {
new Child().say();
}
}
Output is - parent
====================================
Code B -
class Parent {
Integer get() {
return 1;
}
}
class Child extends Parent {
Number get() {
return 2;
}
}
public class Test {
public static void main(String[] args) {
Parent yo = new Child();
System.out.println(yo.get());
}
}
Output is - 1
=============================
Code C
class Grandparent {
String name = "grandparent";
void act() {
System.out.println(name);
}
}
class Parent extends Grandparent {
String name = "parent";
}
public class Test {
public static void main(String[] args) {
Parent yo = new Parent();
yo.act();
}
}
Output is - grandparent
=======================
Thanks
Oracle certified JPA Developer (1Z0-898),Oracle certified Java 8 Programmer I (1Z0-808), Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I, CIW Certified Ecommerce specialist