Android Studio

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.

as_file1
Image 1

Superclass -2
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

Superclass -3
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
#parse(“File Header.java”)
public class ${NAME} extends ${SUPERCLASS} {
}

Apply it and the Click Ok button. as shown below

Superclass 4
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.

as_file1-5

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

SuperClass

That’s it.

You’ll see new Class created with SuperClass.

Hope it helps somebody.

You may also interested in

2 thoughts on “Create new Class extends a SuperClass- Android Studio

  1. 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.