0

What does ABC object=new DEF means ?

When ABC is a parent class and DEF is a child class, and when we define an object in main as :- ABC object= new DEF; Then what does it means ?

3rd Jan 2017, 7:20 AM
SAKSHI DUBEY
SAKSHI DUBEY - avatar
6 Respostas
+ 1
I think the statement is ABC object=new DEF() . This means that object is declared to be of type ABC but it refers to a DEF type object. So ABC is declared type and DEF is actual type.
3rd Jan 2017, 4:45 PM
dawood mansoor
dawood mansoor - avatar
+ 1
sorry for flooding the answer screen. My connection was down. Declared type and Actual type come into play in static and dynamic binding. The logic is simple. Inheritance follows a "is-a" relation. Suppose a class Manager inherits from a class Employee( idea copied from Core Java Vol I by Cay S.Horstmann and Gary Cornell) If a statement such as this is encountered Employee a =new Manager(); a is an Employee. an Employee can either be a normal Employee or a Manager. Suppose class Manager overrides a method getSalary() If we call a.getSalary() the getSalary() of Manager class is called. This is dynamic binding. However if there is a static method of any class which is overridden as 1. static String getGrade(Employee e) 2.static String getGrade(Manager e) Now if we call getGrade(a); the getGrade(Employee e) is called not the other one. This is static binding. However if we declare Manager a =new Employee() it will give an error as a being a Manager cannot refer to a regular Employee.
3rd Jan 2017, 7:15 PM
dawood mansoor
dawood mansoor - avatar
0
I think the statement is ABC object=new DEF() . This means that object is declared to be of type ABC but it refers to a DEF type object. So ABC is declared type and DEF is actual type.
3rd Jan 2017, 4:43 PM
dawood mansoor
dawood mansoor - avatar
0
I think the statement is ABC object=new DEF() . This means that object is declared to be of type ABC but it refers to a DEF type object. So ABC is declared type and DEF is actual type.
3rd Jan 2017, 4:43 PM
dawood mansoor
dawood mansoor - avatar
0
thanks .. but what is meant by declared and actual type and what is the difference between them ?
3rd Jan 2017, 4:53 PM
SAKSHI DUBEY
SAKSHI DUBEY - avatar
0
thanks for the explanation ... now I get the idea
4th Jan 2017, 5:03 AM
SAKSHI DUBEY
SAKSHI DUBEY - avatar