Create new Class extends a SuperClass- Android Studio

In Android studio, If you want to create a new Class extends a SuperClass, built-in menu doesn’t provide option for it.

Create a Class extends a SuperClass

Where as you can only Create a new Class and then manually write down extends Superclass.

Image 1
Image 2

To add Create new Class which extends a SuperClass, you need to Create a new Template

Press Ctrl+Alt+S to open Settings  window, here search for File and Code Templates

Image 3

Click + button to add new template, give a name as Inheritance(you can give any name) and write this below code

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != “”)package ${PACKAGE_NAME};#end
public class ${NAME} extends ${SUPERCLASS} {

Apply it and the Click Ok button. as shown below

Image 4

Now go to project and try to create new class as shown Image 1 above..

and ¬†you’ll see newly added template in dropdown as shown below.


Select it and then you’ll be asked to enter Super class name. Enter your Super class name.


That’s it.

You’ll see new Class created with SuperClass.

Hope it helps somebody.

You may also interested in


1 Comment

  1. Prachi | | Reply

    I tried the same thing but it is displaying some error message: “Unable to parse template Superclass” Error message: Lexical error: org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 1, column 44. Encountered: “\u201c” (8220), after : “”

    Can you please tell what is wrong with my code.

Leave a Reply

Your email address will not be published. Required fields are marked *