Jump to content

How to call a method

Recommended Posts



I have my java as follows:

 public class Test_Final {

	 public void test_non_final () {

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?

Link to post
Share on other sites

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()
Link to post
Share on other sites

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.





Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...