Forum Stats

  • 3,855,262 Users
  • 2,264,493 Discussions
  • 7,905,953 Comments

Discussions

abstract class problem.

870171
870171 Member Posts: 10
hi;

kindly confirm that following statement is true or false

All the abstract methods present in the abstract super-class must be implemented by the first non abstract class.

regards
Pardeep Jangra
Tagged:

Best Answer

«1

Answers

  • 796440
    796440 Member Posts: 19,179 Gold Trophy
    Where did you read that?

    Why do you doubt it?

    What do you think is the answer, and why?
  • 802316
    802316 Member Posts: 532
    edited Jun 21, 2011 7:58AM
    867168 wrote:
    All the abstract methods present in the abstract super-class must be implemented by the first non abstract class.
    Say you could write the following
    abstract class A {
        abstract void method();
    }
    
    class B extends A { }
    
    A a = new B();
    a.method(); // what would you expect to happen here?
  • 870171
    870171 Member Posts: 10
    i got this question from my mind. as from last 2 days i am learning abstract class concept.
    i just want to ask you people that which i am saying is right or wrong.
    if i am wrong then please provide me good examples.

    regards
    pardeep jangra
  • 870171
    870171 Member Posts: 10
    hi;

    thanks for your kind reply.
    let us consider your example i am saying tha
    the method of class a must have body in class B.
    is it true or not?
  • 798692
    798692 Member Posts: 433
    edited Jun 21, 2011 7:50AM
    Not true. Here the method() is not an absract method.
  • 802316
    802316 Member Posts: 532
    Ram wrote:
    Not true. Here the method() is not an absract method.
    Sorry, it was meant to be abstract, there was no body defined
  • EJP
    EJP Member Posts: 32,920 Gold Crown
    Answer ✓
    You are wrong. Consider:
    abstract class A
    {
      abstract void method();
    }
    
    abstract class B extends A
    {
      void method(){}
    }
    
    class C extends B
    {
    }
  • 798692
    798692 Member Posts: 433
    EJP wrote:
    You are wrong. Consider:
    abstract class A
    {
    abstract void method();
    }
    
    abstract class B extends A
    {
    void method(){}
    }
    
    class C extends B
    {
    }
    OP mentioned that first non-abstract class. It is already a part of his point.
  • EJP
    EJP Member Posts: 32,920 Gold Crown
    edited Jun 21, 2011 9:06AM
    OP mentioned that first non-abstract class.
    The OP asked whether 'All the abstract methods present in the abstract super-class must be implemented by the first non abstract class.' I have just demonstrated that this isn't so. Class C is the first non-abstract class and it doesn't implement any methods at all. Ergo the OP is wrong.
    It is already a part of his point.
    It is already part of his question. I have answered it. What exactly you are doing is anybody's guess.
  • 796440
    796440 Member Posts: 19,179 Gold Trophy
    edited Jun 21, 2011 10:23AM
    867168 wrote:
    i got this question from my mind. as from last 2 days i am learning abstract class concept.
    i just want to ask you people that which i am saying is right or wrong.
    1. What do you think, and why

    2. What did you observe when you tested it, an what do those observations tell you?

    The more you show that you've put some effort into answering your own question, the more people will be willing to help you.
This discussion has been closed.