Understand meaning of statement in code - activityCallback = (ToolbarListener) context












0















I am trying to understand the meaning of this line :



activityCallback = (ToolbarListener) context



under the expression -





public class ToolbarFragment extends Fragment implements SeekBar.OnSeekBarChangeListener {


private static int seekValue = 10;
private static EditText editText;

ToolbarListener activityCallback;

public interface ToolbarListener {

public void onButtonClick (int position, String text);

}

@Override
public void onAttach(Context context) {
super.onAttach(context);
try {activityCallback = (ToolbarListener) context;}
catch (ClassCastException e) {
throw new ClassCastException(context.toString() + "must implement ToolBarListener");
}

}




I understand that a reference to context (here Parent Activity) will be created and stored in the activitycallback variable using the above expression.



However, I am unable how to understand how is it possible to cast an interface object to an activity (here context).



I am able to understand the other code in full and my project is working. It is a project in which a parent activity is communicating with two fragments using a listener interface.



I have attached the java files of the whole project in case you may want to review the code.



Regards,
Ravi.



----ToolbarFragment.java-----
package com.ebookfrenzy.fragmentexample;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;

public class ToolbarFragment extends Fragment implements SeekBar.OnSeekBarChangeListener {


private static int seekValue = 10;
private static EditText editText;

ToolbarListener activityCallback;

public interface ToolbarListener {

public void onButtonClick (int position, String text);

}

@Override
public void onAttach(Context context) {
super.onAttach(context);
try {activityCallback = (ToolbarListener) context;}
catch (ClassCastException e) {
throw new ClassCastException(context.toString() + "must implement ToolBarListener");
}

}

@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
// inflate the layout for this fragment

View view = inflater.inflate(R.layout.toolbar_fragment, container,false);

editText = (EditText) view.findViewById(R.id.editText1);
final SeekBar seekBar = view.findViewById(R.id.seekBar1);
seekBar.setOnSeekBarChangeListener(this);
final Button button = view.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonClicked(v);
}
});



return view;
}

private void buttonClicked(View v) {
activityCallback.onButtonClick(seekValue, editText.getText().toString());
}


@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
seekValue = progress;
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
}

-----TextFragment.java----

package com.ebookfrenzy.fragmentexample;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;



public class TextFragment extends Fragment {

private static TextView textView;

@Override
public View onCreateView(
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
// inflate the layout for this fragment

View view = inflater.inflate(R.layout.text_fragment, container, false);
textView = (TextView)view.findViewById(R.id.textView1);
return view;

}

public void changeTextProperties (int fontSize, String text) {
textView.setTextSize(fontSize);
textView.setText(text);

}
}

----FragmentActivity.java----

package com.ebookfrenzy.fragmentexample;

import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class FragmentExampleActivity extends FragmentActivity
implements ToolbarFragment.ToolbarListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment_example);
}

@Override
public void onButtonClick(int fontSize, String text) {
TextFragment textFragment = (TextFragment)
getSupportFragmentManager().findFragmentById(R.id.text_fragment);
textFragment.changeTextProperties(fontSize, text);

}
}









share|improve this question



























    0















    I am trying to understand the meaning of this line :



    activityCallback = (ToolbarListener) context



    under the expression -





    public class ToolbarFragment extends Fragment implements SeekBar.OnSeekBarChangeListener {


    private static int seekValue = 10;
    private static EditText editText;

    ToolbarListener activityCallback;

    public interface ToolbarListener {

    public void onButtonClick (int position, String text);

    }

    @Override
    public void onAttach(Context context) {
    super.onAttach(context);
    try {activityCallback = (ToolbarListener) context;}
    catch (ClassCastException e) {
    throw new ClassCastException(context.toString() + "must implement ToolBarListener");
    }

    }




    I understand that a reference to context (here Parent Activity) will be created and stored in the activitycallback variable using the above expression.



    However, I am unable how to understand how is it possible to cast an interface object to an activity (here context).



    I am able to understand the other code in full and my project is working. It is a project in which a parent activity is communicating with two fragments using a listener interface.



    I have attached the java files of the whole project in case you may want to review the code.



    Regards,
    Ravi.



    ----ToolbarFragment.java-----
    package com.ebookfrenzy.fragmentexample;

    import android.content.Context;
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.SeekBar;

    public class ToolbarFragment extends Fragment implements SeekBar.OnSeekBarChangeListener {


    private static int seekValue = 10;
    private static EditText editText;

    ToolbarListener activityCallback;

    public interface ToolbarListener {

    public void onButtonClick (int position, String text);

    }

    @Override
    public void onAttach(Context context) {
    super.onAttach(context);
    try {activityCallback = (ToolbarListener) context;}
    catch (ClassCastException e) {
    throw new ClassCastException(context.toString() + "must implement ToolBarListener");
    }

    }

    @Override
    public View onCreateView(LayoutInflater inflater,
    ViewGroup container,
    Bundle savedInstanceState) {
    // inflate the layout for this fragment

    View view = inflater.inflate(R.layout.toolbar_fragment, container,false);

    editText = (EditText) view.findViewById(R.id.editText1);
    final SeekBar seekBar = view.findViewById(R.id.seekBar1);
    seekBar.setOnSeekBarChangeListener(this);
    final Button button = view.findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    buttonClicked(v);
    }
    });



    return view;
    }

    private void buttonClicked(View v) {
    activityCallback.onButtonClick(seekValue, editText.getText().toString());
    }


    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    seekValue = progress;
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
    }

    -----TextFragment.java----

    package com.ebookfrenzy.fragmentexample;

    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;



    public class TextFragment extends Fragment {

    private static TextView textView;

    @Override
    public View onCreateView(
    LayoutInflater inflater,
    ViewGroup container,
    Bundle savedInstanceState) {
    // inflate the layout for this fragment

    View view = inflater.inflate(R.layout.text_fragment, container, false);
    textView = (TextView)view.findViewById(R.id.textView1);
    return view;

    }

    public void changeTextProperties (int fontSize, String text) {
    textView.setTextSize(fontSize);
    textView.setText(text);

    }
    }

    ----FragmentActivity.java----

    package com.ebookfrenzy.fragmentexample;

    import android.app.Activity;
    import android.support.v4.app.FragmentActivity;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;

    public class FragmentExampleActivity extends FragmentActivity
    implements ToolbarFragment.ToolbarListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment_example);
    }

    @Override
    public void onButtonClick(int fontSize, String text) {
    TextFragment textFragment = (TextFragment)
    getSupportFragmentManager().findFragmentById(R.id.text_fragment);
    textFragment.changeTextProperties(fontSize, text);

    }
    }









    share|improve this question

























      0












      0








      0








      I am trying to understand the meaning of this line :



      activityCallback = (ToolbarListener) context



      under the expression -





      public class ToolbarFragment extends Fragment implements SeekBar.OnSeekBarChangeListener {


      private static int seekValue = 10;
      private static EditText editText;

      ToolbarListener activityCallback;

      public interface ToolbarListener {

      public void onButtonClick (int position, String text);

      }

      @Override
      public void onAttach(Context context) {
      super.onAttach(context);
      try {activityCallback = (ToolbarListener) context;}
      catch (ClassCastException e) {
      throw new ClassCastException(context.toString() + "must implement ToolBarListener");
      }

      }




      I understand that a reference to context (here Parent Activity) will be created and stored in the activitycallback variable using the above expression.



      However, I am unable how to understand how is it possible to cast an interface object to an activity (here context).



      I am able to understand the other code in full and my project is working. It is a project in which a parent activity is communicating with two fragments using a listener interface.



      I have attached the java files of the whole project in case you may want to review the code.



      Regards,
      Ravi.



      ----ToolbarFragment.java-----
      package com.ebookfrenzy.fragmentexample;

      import android.content.Context;
      import android.os.Bundle;
      import android.support.v4.app.Fragment;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.Button;
      import android.widget.EditText;
      import android.widget.SeekBar;

      public class ToolbarFragment extends Fragment implements SeekBar.OnSeekBarChangeListener {


      private static int seekValue = 10;
      private static EditText editText;

      ToolbarListener activityCallback;

      public interface ToolbarListener {

      public void onButtonClick (int position, String text);

      }

      @Override
      public void onAttach(Context context) {
      super.onAttach(context);
      try {activityCallback = (ToolbarListener) context;}
      catch (ClassCastException e) {
      throw new ClassCastException(context.toString() + "must implement ToolBarListener");
      }

      }

      @Override
      public View onCreateView(LayoutInflater inflater,
      ViewGroup container,
      Bundle savedInstanceState) {
      // inflate the layout for this fragment

      View view = inflater.inflate(R.layout.toolbar_fragment, container,false);

      editText = (EditText) view.findViewById(R.id.editText1);
      final SeekBar seekBar = view.findViewById(R.id.seekBar1);
      seekBar.setOnSeekBarChangeListener(this);
      final Button button = view.findViewById(R.id.button1);
      button.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      buttonClicked(v);
      }
      });



      return view;
      }

      private void buttonClicked(View v) {
      activityCallback.onButtonClick(seekValue, editText.getText().toString());
      }


      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      seekValue = progress;
      }

      @Override
      public void onStartTrackingTouch(SeekBar seekBar) {

      }

      @Override
      public void onStopTrackingTouch(SeekBar seekBar) {

      }
      }

      -----TextFragment.java----

      package com.ebookfrenzy.fragmentexample;

      import android.os.Bundle;
      import android.support.v4.app.Fragment;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.TextView;



      public class TextFragment extends Fragment {

      private static TextView textView;

      @Override
      public View onCreateView(
      LayoutInflater inflater,
      ViewGroup container,
      Bundle savedInstanceState) {
      // inflate the layout for this fragment

      View view = inflater.inflate(R.layout.text_fragment, container, false);
      textView = (TextView)view.findViewById(R.id.textView1);
      return view;

      }

      public void changeTextProperties (int fontSize, String text) {
      textView.setTextSize(fontSize);
      textView.setText(text);

      }
      }

      ----FragmentActivity.java----

      package com.ebookfrenzy.fragmentexample;

      import android.app.Activity;
      import android.support.v4.app.FragmentActivity;
      import android.support.v7.app.AppCompatActivity;
      import android.os.Bundle;

      public class FragmentExampleActivity extends FragmentActivity
      implements ToolbarFragment.ToolbarListener{

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_fragment_example);
      }

      @Override
      public void onButtonClick(int fontSize, String text) {
      TextFragment textFragment = (TextFragment)
      getSupportFragmentManager().findFragmentById(R.id.text_fragment);
      textFragment.changeTextProperties(fontSize, text);

      }
      }









      share|improve this question














      I am trying to understand the meaning of this line :



      activityCallback = (ToolbarListener) context



      under the expression -





      public class ToolbarFragment extends Fragment implements SeekBar.OnSeekBarChangeListener {


      private static int seekValue = 10;
      private static EditText editText;

      ToolbarListener activityCallback;

      public interface ToolbarListener {

      public void onButtonClick (int position, String text);

      }

      @Override
      public void onAttach(Context context) {
      super.onAttach(context);
      try {activityCallback = (ToolbarListener) context;}
      catch (ClassCastException e) {
      throw new ClassCastException(context.toString() + "must implement ToolBarListener");
      }

      }




      I understand that a reference to context (here Parent Activity) will be created and stored in the activitycallback variable using the above expression.



      However, I am unable how to understand how is it possible to cast an interface object to an activity (here context).



      I am able to understand the other code in full and my project is working. It is a project in which a parent activity is communicating with two fragments using a listener interface.



      I have attached the java files of the whole project in case you may want to review the code.



      Regards,
      Ravi.



      ----ToolbarFragment.java-----
      package com.ebookfrenzy.fragmentexample;

      import android.content.Context;
      import android.os.Bundle;
      import android.support.v4.app.Fragment;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.Button;
      import android.widget.EditText;
      import android.widget.SeekBar;

      public class ToolbarFragment extends Fragment implements SeekBar.OnSeekBarChangeListener {


      private static int seekValue = 10;
      private static EditText editText;

      ToolbarListener activityCallback;

      public interface ToolbarListener {

      public void onButtonClick (int position, String text);

      }

      @Override
      public void onAttach(Context context) {
      super.onAttach(context);
      try {activityCallback = (ToolbarListener) context;}
      catch (ClassCastException e) {
      throw new ClassCastException(context.toString() + "must implement ToolBarListener");
      }

      }

      @Override
      public View onCreateView(LayoutInflater inflater,
      ViewGroup container,
      Bundle savedInstanceState) {
      // inflate the layout for this fragment

      View view = inflater.inflate(R.layout.toolbar_fragment, container,false);

      editText = (EditText) view.findViewById(R.id.editText1);
      final SeekBar seekBar = view.findViewById(R.id.seekBar1);
      seekBar.setOnSeekBarChangeListener(this);
      final Button button = view.findViewById(R.id.button1);
      button.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      buttonClicked(v);
      }
      });



      return view;
      }

      private void buttonClicked(View v) {
      activityCallback.onButtonClick(seekValue, editText.getText().toString());
      }


      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      seekValue = progress;
      }

      @Override
      public void onStartTrackingTouch(SeekBar seekBar) {

      }

      @Override
      public void onStopTrackingTouch(SeekBar seekBar) {

      }
      }

      -----TextFragment.java----

      package com.ebookfrenzy.fragmentexample;

      import android.os.Bundle;
      import android.support.v4.app.Fragment;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.TextView;



      public class TextFragment extends Fragment {

      private static TextView textView;

      @Override
      public View onCreateView(
      LayoutInflater inflater,
      ViewGroup container,
      Bundle savedInstanceState) {
      // inflate the layout for this fragment

      View view = inflater.inflate(R.layout.text_fragment, container, false);
      textView = (TextView)view.findViewById(R.id.textView1);
      return view;

      }

      public void changeTextProperties (int fontSize, String text) {
      textView.setTextSize(fontSize);
      textView.setText(text);

      }
      }

      ----FragmentActivity.java----

      package com.ebookfrenzy.fragmentexample;

      import android.app.Activity;
      import android.support.v4.app.FragmentActivity;
      import android.support.v7.app.AppCompatActivity;
      import android.os.Bundle;

      public class FragmentExampleActivity extends FragmentActivity
      implements ToolbarFragment.ToolbarListener{

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_fragment_example);
      }

      @Override
      public void onButtonClick(int fontSize, String text) {
      TextFragment textFragment = (TextFragment)
      getSupportFragmentManager().findFragmentById(R.id.text_fragment);
      textFragment.changeTextProperties(fontSize, text);

      }
      }






      android-studio interface fragment






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 8:34









      Ravi AgrawalRavi Agrawal

      52




      52
























          1 Answer
          1






          active

          oldest

          votes


















          0














          There might be several different activities that could host this fragment in different circumstances. So, we make a rule: any activity that hosts this fragment must implement ToolbarListener. That interface defines the "contract" between the fragment and the activities that host it. In onAttach(), we validate that the context is an ToolbarListener, then go ahead and save the cast to ToolbarListener for later use.



          As the activity implements ToolbarListener so the ToolbarListener will be Parent of the implemented Activity's object. Hence you can Type cast it.






          share|improve this answer
























          • @RaviAgrawal Actually In Case of Object typecasting, the classes we need to typecast to other Class must be related by inheritence. As per my understanding, comparing properties is not the case .

            – Aman Rawat
            Jan 2 at 10:24











          • Thanks for taking the time to answer. This does clear up the confusion. Have a good day, Sir.

            – Ravi Agrawal
            Jan 2 at 10:25











          • @RaviAgrawal Happy to help.

            – Aman Rawat
            Jan 2 at 10:32











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003324%2funderstand-meaning-of-statement-in-code-activitycallback-toolbarlistener-c%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          There might be several different activities that could host this fragment in different circumstances. So, we make a rule: any activity that hosts this fragment must implement ToolbarListener. That interface defines the "contract" between the fragment and the activities that host it. In onAttach(), we validate that the context is an ToolbarListener, then go ahead and save the cast to ToolbarListener for later use.



          As the activity implements ToolbarListener so the ToolbarListener will be Parent of the implemented Activity's object. Hence you can Type cast it.






          share|improve this answer
























          • @RaviAgrawal Actually In Case of Object typecasting, the classes we need to typecast to other Class must be related by inheritence. As per my understanding, comparing properties is not the case .

            – Aman Rawat
            Jan 2 at 10:24











          • Thanks for taking the time to answer. This does clear up the confusion. Have a good day, Sir.

            – Ravi Agrawal
            Jan 2 at 10:25











          • @RaviAgrawal Happy to help.

            – Aman Rawat
            Jan 2 at 10:32
















          0














          There might be several different activities that could host this fragment in different circumstances. So, we make a rule: any activity that hosts this fragment must implement ToolbarListener. That interface defines the "contract" between the fragment and the activities that host it. In onAttach(), we validate that the context is an ToolbarListener, then go ahead and save the cast to ToolbarListener for later use.



          As the activity implements ToolbarListener so the ToolbarListener will be Parent of the implemented Activity's object. Hence you can Type cast it.






          share|improve this answer
























          • @RaviAgrawal Actually In Case of Object typecasting, the classes we need to typecast to other Class must be related by inheritence. As per my understanding, comparing properties is not the case .

            – Aman Rawat
            Jan 2 at 10:24











          • Thanks for taking the time to answer. This does clear up the confusion. Have a good day, Sir.

            – Ravi Agrawal
            Jan 2 at 10:25











          • @RaviAgrawal Happy to help.

            – Aman Rawat
            Jan 2 at 10:32














          0












          0








          0







          There might be several different activities that could host this fragment in different circumstances. So, we make a rule: any activity that hosts this fragment must implement ToolbarListener. That interface defines the "contract" between the fragment and the activities that host it. In onAttach(), we validate that the context is an ToolbarListener, then go ahead and save the cast to ToolbarListener for later use.



          As the activity implements ToolbarListener so the ToolbarListener will be Parent of the implemented Activity's object. Hence you can Type cast it.






          share|improve this answer













          There might be several different activities that could host this fragment in different circumstances. So, we make a rule: any activity that hosts this fragment must implement ToolbarListener. That interface defines the "contract" between the fragment and the activities that host it. In onAttach(), we validate that the context is an ToolbarListener, then go ahead and save the cast to ToolbarListener for later use.



          As the activity implements ToolbarListener so the ToolbarListener will be Parent of the implemented Activity's object. Hence you can Type cast it.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 10:11









          Aman RawatAman Rawat

          1829




          1829













          • @RaviAgrawal Actually In Case of Object typecasting, the classes we need to typecast to other Class must be related by inheritence. As per my understanding, comparing properties is not the case .

            – Aman Rawat
            Jan 2 at 10:24











          • Thanks for taking the time to answer. This does clear up the confusion. Have a good day, Sir.

            – Ravi Agrawal
            Jan 2 at 10:25











          • @RaviAgrawal Happy to help.

            – Aman Rawat
            Jan 2 at 10:32



















          • @RaviAgrawal Actually In Case of Object typecasting, the classes we need to typecast to other Class must be related by inheritence. As per my understanding, comparing properties is not the case .

            – Aman Rawat
            Jan 2 at 10:24











          • Thanks for taking the time to answer. This does clear up the confusion. Have a good day, Sir.

            – Ravi Agrawal
            Jan 2 at 10:25











          • @RaviAgrawal Happy to help.

            – Aman Rawat
            Jan 2 at 10:32

















          @RaviAgrawal Actually In Case of Object typecasting, the classes we need to typecast to other Class must be related by inheritence. As per my understanding, comparing properties is not the case .

          – Aman Rawat
          Jan 2 at 10:24





          @RaviAgrawal Actually In Case of Object typecasting, the classes we need to typecast to other Class must be related by inheritence. As per my understanding, comparing properties is not the case .

          – Aman Rawat
          Jan 2 at 10:24













          Thanks for taking the time to answer. This does clear up the confusion. Have a good day, Sir.

          – Ravi Agrawal
          Jan 2 at 10:25





          Thanks for taking the time to answer. This does clear up the confusion. Have a good day, Sir.

          – Ravi Agrawal
          Jan 2 at 10:25













          @RaviAgrawal Happy to help.

          – Aman Rawat
          Jan 2 at 10:32





          @RaviAgrawal Happy to help.

          – Aman Rawat
          Jan 2 at 10:32




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003324%2funderstand-meaning-of-statement-in-code-activitycallback-toolbarlistener-c%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]