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

  • SEARCH
  • Home
  • 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 6096013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:52:38+00:00 2026-05-23T12:52:38+00:00

1) OnCreate is public method of instantiated object from ClsLast class. But I wanted

  • 0

1) OnCreate is public method of instantiated object from ClsLast class. But I wanted to restrict OnCreate method as protected.

interface InterFace {
    void OnCreate();
}

class ClsFirst implements InterFace {
    @Override
    public void OnCreate() { }

}

class ClsLast extends ClsFirst{ }

class Test {
    static void main(){
        ClsLast objClsAct = new ClsLast();
        objClsAct.OnCreate();
    }
}

2) If I set OnCreate method as protected in InterFace

interface InterFace {
    protected void OnCreate();
}   

I’m getting error like this:
Illegal modifier for the interface method OnCreate; only public & abstract are permitted

3) If I set protected the method inside the ClsFirst class which implements InterFace like this:

interface InterFace {
    void OnCreate();
}   

class ClsFirst implements InterFace {
    @Override
    protected void OnCreate() { }

}

I’m getting this error:
Cannot reduce the visibility of the inherited method from InterFace

4) When I change the ClsFirst as abstract class and implements InterFace

interface InterFace {
    void OnCreate();
}   

abstract class ClsFirst implements InterFace {

}

I haven’t to implement OnCreate method inside the ClsFirst class but ClsLast why?

Summary

  1. How can I set Interface methods can only be used in derived classes?
  2. Why can’t I set methods with protected access inside Interface?
  3. Why can’t I set the accessor type of Class different than public after I implement the InterFace?
  4. abstract classes that even if they implements an interface don’t have to add unimplemented methods itself until one class derives abstracted classes. Why?

Thank you so much for your kind answers from now.

  • 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-23T12:52:38+00:00Added an answer on May 23, 2026 at 12:52 pm

    An interfaceis per definition a public contract. By implementing an interface you promise to provide a set of methods (and properties in other languages).

    An interface has nothing in common with abstract classes because you can implement as many interfaces as you want on a single class and you implement instead of derive from it.

    An abstract class is a base class, its like a partially functionally base which is used to share implementation details between different classes and provides a contract, too. However it’s more an internal contract for all derived classes. Most times abstract classes are used to force all derived classes into a common pattern instead of sharing a public contract.

    An abstract class can force a derived class to implement a method (or provide a suitable default implementation using the virtual keyword) and take use of this method (this is called Template Pattern).

    If you implement an interface on an abstract class you don’t have to provide all interface methods because the abstract class can not be instantiated. However if you don’t implement all interface methods the first non abstract class in your hierarchy has to provide the missing methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Activity we have method @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); //... } My
I'm creating a new SQLite database in Android via this method: public void onCreate(SQLiteDatabase
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); savedInstanceState.putString(foo, bar); } @Override public void
@Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); // providers data // db.execSQL(insert into //
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Init(); backthread tr=new backthread(); tr.execute(0,0,0); } backthread
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map); TextView lattv=(TextView)findViewById(R.id.lat); TextView lngtv=(TextView)findViewById(R.id.lng); JSONParstring jParser =
My Code:- public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); // defining the WebView WebView
My timer code is: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initializer(); fire.setOnClickListener(this); }
I am setting a animation on the imageview public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
I draw an arc using onDraw(canvas) : @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

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.