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 7435001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:59:13+00:00 2026-05-29T09:59:13+00:00

Suppose I have two Classes, A and B. The A class is defined as

  • 0

Suppose I have two Classes, A and B. The A class is defined as abstract, while B extends this abstract class, and finally i test the result and both classes are part of same package.

public abstract class A {

    protected abstract void method1(); 

    protected void method2() { 
        System.out.println("This is Class A's method"); 
    } 
}

public class B extends A {

    @Override
    protected void method1() {
        System.out.println("This is B's implementaiton of A's method");
    } 
}  

and now when i test them:

B b = new B();
b.method1();
b.method2();  

I get expected output:

This is B's implementaiton of A's method
This is Class A's method

QUESTIONS:

  • What is the purpose of @Override keyword, because if I omit it, it
    still works the same.
  • If I don’t implement the abstract method, I get a compilation error. So what is the difference from implementing an interface?
  • Also, I can implement method2() in B as well. Then the output changes to what is use in B. Isn’t this also overriding the parent class method? Then what is the purpose of explicitly defining a method as abstract in Class A?
  • 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-29T09:59:14+00:00Added an answer on May 29, 2026 at 9:59 am

    @Override

    @Override was introduced in Java 5 (and extended a little bit in Java 6). It’s only informative. It says “I’m suppose to override something that already exist in parent class or interface.

    IDE’s like Eclipse can warn you in case there’s no such parent method (by example if you mispell the name). In that case your method will not be invoked (because of the mispelling).

    But don’t worry too much about it.

    Abstract class vs interface

    An abstract class allows you define a basic functionality leaving undefined parts. An interface doesn’t allow you to implement anything. You can program everything except the part that really changes in each case. So when you need it, you inherit and implement the missing part.

    Override two methods

    Yes. In Java you can override all methods not explicity declared as final in parent class. It’s ok. If you want to make it unmodifiable you can declare it final. By example, if you want to declare an ordering you could:

    public abstract class Ordering<X>
    {
    abstract boolean isLower(X a, X b);
    abstract boolean isEquals(X a, X b);
       final boolean isGreater(X a, X b) {
          return !isLower(a, b) && !isEquals(a, b);
       }
    }
    

    Of course it may have sense to override isGreater to implement it another more efficient way (imagine it’s costly to compare). But there are scenarios when you want to provide basic already implemented functionality (and then’s when abstract classes are better than interfaces) or when you want to force some implementation (then’s when final keyword show useful).

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

Sidebar

Related Questions

Suppose I have two classes defined the following way: public class A { public
suppose I have two classes class A extends class B class A has its
Suppose I have two classes deriving from a third abstract class: public abstract class
suppose you have two (or more) classes with private member vectors: class A {
Suppose I have two classes that both contain a static variable, XmlTag. The second
Suppose we have following two classes: class Temp{ public: char a; char b; };
I have two classes: abstract Entity , abstract ClassA extends Entity , ClassB extends
Suppose I have two classes class A { b bInstance; public A ( b
The scenario Suppose I have the following two model classes: public class ProductColor {
Suppose I have two classes: public class Student { public int Id {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.