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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:23:07+00:00 2026-05-26T15:23:07+00:00

Let’s look at the following simple code snippet in Java. interface Sum { abstract

  • 0

Let’s look at the following simple code snippet in Java.

interface Sum
{
    abstract public void showSum();
}

interface Mul
{
    abstract public void showMul();
}

abstract class Super implements Sum
{
    protected int x;
    protected int y;

    public Super(int x, int y)
    {
        this.x=x;
        this.y=y;
    }

    //No error, though the method showSum() of the implementing iterface Sum is commented. Why?

    /*public void showSum()
    {
        System.out.println("Sum = "+(x+y));
    }*/
}

final class Calculation extends Super implements Mul
{
    public Calculation(int x, int y)
    {
        super(x,y);
    }

    public void showSum()
    {
        System.out.println("Summation = "+(x+y));
    }

    //If showMul() is commented , it would issue a compile-time error. Why?
    public void showMul()
    {
        System.out.println("Multiplication = "+(x*y));
    }   
}

final public class Main
{
    public static void main(String[] args) throws IOException
    {
        Scanner s=new Scanner(System.in);

        System.out.print("\nEnter a number : ");
        int x=s.nextInt();

        System.out.print("\nEnter another number : ");
        int y=s.nextInt();

        Calculation c=new Calculation(x,y);
        c.showSum();
        c.showMul();
    }
}

Since the interface Sum containing only one method showSum(); is being implemented by the abstract class Super , there should be necessary for the abstract class Super to implement that method showSum();. The compiler however doesn’t complain at all and the program is working well with no problem at all. Why?


Similarly, the non-abstract final class Calculation is implementing the Mul interface and contains the actual implementation of the method showMul(); presented in it’s implementing interface. In case, if this method showMul() in the class Calculation is commented, it issues a compile-time error. Why is the same thing not applicable to that abstract class Super?

  • 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-26T15:23:08+00:00Added an answer on May 26, 2026 at 3:23 pm

    The abstract class is not real implementation class. It may contain abstract methods and doesnot need to implement the methods from the interface. It is concern of the REAL implementing class to define the abstract/interface methods.

    See this difference between abstract class and interface

    Interface:
    public interface InterfaceClass {
        void interfaceMethod();
        //no method definition
    }
    
    
    //Abstract Class implementing InterfaceClass
    abstract class AbsClass implements InterfaceClass{
        abstract void abstractMethod();
        public void doSomethingCommon() {
            System.out.println("Abstract class may contain method definition");
        }
        //no need to implement methods of InterfaceClass because AbsClass is abstract
    }
    

    And here is real class that extends AbsClass: Its duty of RealClass to define all abstract methods and interface methods. Additionally, it may override the defined methods in abstract class as well.

    public class RealClass extends AbsClass{
        @Override
        public void interfaceMethod() {
            //implement interface method here
        }
        @Override
        void abstractMethod() {
        }
        // you may override the doSomethingCommon() of AbsClass too
        @Override
        public void doSomethingCommon() {
            // TODO Auto-generated method stub
            super.doSomethingCommon();
        }
    }
    

    Why there is no compile time error on AbsClass:
    We cannot create instances of abstract class. That’s why there is no meaning of displaying error at compile time.

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

Sidebar

Related Questions

Let's say I have the following entity: public class Store { public List<Product> Products
Let's say I have the following code: Sub TestRangeLoop() Dim rng As Range Set
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say I have the following within my source code, and I want to
let me start by saying it may look simple but im finding it extremely
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a class like this: public class Person { private String
Let's say I have this: public DefaultListModel model = new DefaultListModel(); how do i
let's say I have the following string: string s = A B C D

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.