1

I am learning android and I am newbie. I encountered a code i.e.

FramgmentManager fm = getFragmentManager();

I know that getFragmentManager() is a method defined in Activity class.

In java we access method through object reference that is obj.method() but here how can we call getFragmentMananger without any object refrence

Zameer Ansari
  • 28,977
  • 24
  • 140
  • 219
Vipin Dubey
  • 582
  • 1
  • 9
  • 26

1 Answers1

3

In your case there is an 'automatic' this reference meaning that your method is called on the enclosing object you're using right now (an Activity).

Zielony
  • 16,239
  • 6
  • 34
  • 39
  • and what about method setContentView().Is this method same as this.setcContentView() – Vipin Dubey Dec 29 '15 at 16:39
  • class student{ String hello(){ return "aaaaa"; } } public class Dell extends student{ public static void main(String[] args) { System.out.println("...."); String a= hello(); } } bur here why it is error in line...String a=hello(); why it cant be this.hello(); – Vipin Dubey Dec 29 '15 at 16:59
  • In a static method, like main, there is no `this` to refer to. – Louis Wasserman Dec 29 '15 at 17:21