Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7671339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:01:41+00:00 2026-05-31T16:01:41+00:00

Class parent { protected void myMethod() { if(someCodition) { //return this as well as

  • 0
Class parent {

protected void myMethod() {
 if(someCodition) {
 //return this as well as child's myMethod.
  }
}

Class child extends Parent {

@override
protected void myMethod() {
super.myMethod();
 //code below this line should not execute if someCondition.
 //want parent to handle all this
  }
}

Please don’t suggest to take some boolean flag kind of thing in parent class and check it in child. actually child class will be used by other developers and i dont want them to take care about any such condition, so want to exit from parent itself.

I am fully aware that it is violation of Abstraction principle of oops, but its my need to violate .

Updating

PS: to call myMethod() is not in either child or parent’s control , so can not create a separate method as mentioned in one answer .
actually its and API method, so system will execute it automatically as per need, and i can not stop to call it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:01:43+00:00Added an answer on May 31, 2026 at 4:01 pm

    You are probably looking for template method pattern [or some variation of it]

    The user will override the protected method myTemplateMethod(), and myMethod() will not be overriden.

    myMethod() will invoke super.myMethod() [it was not overriden so actually the super will be invoked immidiately], and the super will invoke [if conditions are met] myTemplateMethod()

    Something along the lines of [pseudo code]:

    abstract Class parent {
    
    protected abstract void myTemplateMethod();
    
    protected final void myMethod() {
     if(someCodition) {
        myTemplateMethod();
      }
    }
    
    Class child extends Parent {
    
    @override
    protected void myTemplateMethod() {
     //code that will be invoked only if someCodition is met
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*
In the below code the Consumer class can access the protected method of Parent
Example models: class Parent(models.Model): name = models.CharField() def __unicode__(self): return self.name class Child(models.Model): parent
I have a base class Parent like this: using System; using System.Collections.Generic; using System.Text;
here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
I've got a class that looks something like this: public class Parent { public
I have a Parent/Child object/mapping as follows: class Parent { int Id; string name;
I got a scenario like this Class Parent { Property A; } Class A
Say I have the following code: class Parent { static string MyField = ParentField;
I have two entities: public class Parent() { public ICollection<Child> Children { get; set;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.