• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Method Invocation

 
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a question. I have written two java files.

1). a.java as


package CertificationPractice.Package1;
public class a
{
public static String doRooThings()
{
System.out.println("Lol");
return null;
}
}

and b.java as

package CertificationPractice.Package2;
import CertificationPractice.Package1.a;

class b extends a
{
public static void main(String args[])
{
System.out.println(doRooThings());
}
}


Now, if U can see in b.java, I am calling the inherited method doRooThings() but I have not created objects for either of the classes. So how is this possible? Both the files are compiling fine and b.java is running fine too.


Thanks
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Arjun Reddy
I think it is logical that the two files compile fine and run
I don't think that you have to make objects of any one of the classes
Class b extends A and A has a static method that you can call it directly in the static main method
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For calling static method we dont need any reference... thats why....
 
reply
    Bookmark Topic Watch Topic
  • New Topic