RSS Feed

Android Studio What Is, What Does @override Do?

I see a lot of questions like what is/ what does “@override” do?

Your code does not require @override to work correctly. @override It is something the compiler uses to help you. You are telling the compiler that you are overriding a method/function in the class you are inheriting from. Why is it useful to do this?. Well once the compiler knows that you intend to override it can help you identify errors in your code.

For example, let us say you have inherited from a class called Person. It has a method getName().

Now in your inherited class you mistype getName() as getname().

Without the @override statement the compiler will be happy.

However you with @override you will get an error because the compiler will not find a method in the parent class called getname() because you mistyped it. The compiler will point this out to you. So @override helps.. 🙂


2 responses »

  1. in your example, so when i do not user override, is the program still running well…?

    • Yes

      Your program will work fine without it. It is not necessary.

      It is something that helps you spot errors – that is all. But it is better to use it because it will warn you about common errors.

      Hope that helps..


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: