newcoder1010 3 Report post Posted November 3, 2016 Hello, I have my java as follows: public class Test_Final { public void test_non_final () { System.out.println("hello");} } public class Test_Final_Caller extends Test_Final{ // separate file public static void main(String args[]) { Test_Final_Caller S1 = new Test_Final_Caller(); System.out.println(S1.test_final_method()); // error here System.out.println(S1.test_non_final()); // error here } } I am not able to print hello from Test_Final_Caller. Can you advise? Share this post Link to post Share on other sites
Ingolme 938 Report post Posted November 3, 2016 What does the error message say? Your functions don't return anything, so there's nothing to print out to the system. Use this function instead for testing: public static void main(String args[]) { Test_Final_Caller S1 = new Test_Final_Caller() S1.test_non_final(); } Share this post Link to post Share on other sites
newcoder1010 3 Report post Posted November 3, 2016 Now, it is working. Thanks. Share this post Link to post Share on other sites
davej 251 Report post Posted November 4, 2016 I'm not sure what you are trying to do but you should probably read some online tutorials on inheritance, upcasting, downcasting, and polymorphism. Share this post Link to post Share on other sites
newcoder1010 3 Report post Posted November 4, 2016 Trying to go thru tutorial in http://www.w3schools.in/java-tutorial/aggregation/. Is it a typo in your site? public class stud{ public static void main(String args[]){ college a = new college(); college b = new univ(); a.move(); b.move(); } } 4th line, Instead of college b = new univ(); , should it be univ b = new univ(); ? Share this post Link to post Share on other sites
davej 251 Report post Posted November 4, 2016 Actually w3schools.in is unaffiliated with w3schools.com (at least AFAIK) The question you are asking is related to polymorphism. A subclass can be declared as a superclass, as in the following... Bicycle bike01 = new Bicycle(20, 10, 1); Bicycle bike02 = new MountainBike(20, 10, 5, "Dual"); Bicycle bike03 = new RoadBike(40, 20, 8, 23); Assuming the MountainBike and RoadBike classes both extend (inherit) the Bicycle class. See... https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html Share this post Link to post Share on other sites
newcoder1010 3 Report post Posted November 4, 2016 Thank you so much. I have long way to go. Yes, I am going thru online tutorials. Share this post Link to post Share on other sites