Results 1 to 17 of 17
Like Tree3Likes
  • 1 Post By jim829
  • 1 Post By Tolls
  • 1 Post By SurfMan

Thread: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Libra..

  1. #1
    misscoding is offline Member
    Join Date
    Apr 2017
    Posts
    4
    Rep Power
    0

    Default Class A extends B, and Class B implements Interface C - what is B? (Abstract, Libra..

    Hi

    I've been looking for a friendly forum for learners. This question has me puzzled. I would be very grateful for some help ...


    (* I think it's one of these. It's not a library class, no suggestion of a reference code/something already written. It's not Abstract class, because it's implementing Class C and to be abstract you need at least one abstract method in B, here it has to implement all of C. It's not a static class because in Java it would be an inner class, not like here.)

    Class A extends Class B and B implements Interface C - what does it imply about the form of Class B?

    A. Generic class *

    B. Library class

    C. Static class

    D. Abstract class

    E. None of the above. *

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    Well,

    Not A. No type parameters.
    B. May or may not be a library class.
    C. May or may not be a static class.
    D. May or may not be an abstract class.

    Guess what?

    Regards,
    Jim
    Tolls likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    misscoding is offline Member
    Join Date
    Apr 2017
    Posts
    4
    Rep Power
    0

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    Thanks Jim.

    Apparently the answer is that it's an abstract class.

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    What kind of weird quiz is that? What defines a "generic class" and what defines a "library class"?? And B does not have to be abstract at all. B can implement all of C's methods and still be either abstract or not. That's exactly how adapters work:

    Java Code:
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    
    class MyMouseAdapter implements MouseListener {
        @Override
        public void mouseClicked(MouseEvent e) {
            
        }
    
        @Override
        public void mousePressed(MouseEvent e) {
    
        }
    
        @Override
        public void mouseReleased(MouseEvent e) {
    
        }
    
        @Override
        public void mouseEntered(MouseEvent e) {
    
        }
    
        @Override
        public void mouseExited(MouseEvent e) {
    
        }
    } 
    
    class DefaultMouseAdapter extends MyMouseAdapter {
        @Override
        public void mouseClicked(MouseEvent e) {
            //only interested in this.
        }
    }

    Did you dig this stuff up at roseindia.net or something?
    Last edited by SurfMan; 04-28-2017 at 02:58 PM.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    Where did you get this question from?
    Have you posted it exactly as it is presented to you?
    Because as it stands, the answer is that it doesn't imply any of the above.
    benji2505 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    I don't blame you but apparently the person or site providing the question doesn't know what they are talking about.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    Quote Originally Posted by SurfMan View Post
    Did you dig this stuff up at roseindia.net or something?
    LOL!!

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    misscoding is offline Member
    Join Date
    Apr 2017
    Posts
    4
    Rep Power
    0

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    Quote Originally Posted by jim829 View Post
    I don't blame you but apparently the person or site providing the question doesn't know what they are talking about.

    Regards,
    Jim
    It's from a 1st year undergrad Comp Sci course. @_@ And yes posted EXACTLY as it is.

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    Well, here it is with no abstract class involved.

    Java Code:
    interface C {
       public void doSomething();
    }
    
    class B implements C {
      public void doSomething() {
         System.out.println("Doing something.");
      }
    }
    
    public class A extends B{
       public static void main(String[] args) {
          A a = new A();
          a.doSomething();
       }
    }
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    Here is my 2 cents: the question is what this setup implies, so how and where you would see this kind of implementation. If a class implements an interface, it has to implement all interface methods, unless - !! - it is abstract. In these cases the omitted method(s) is/are then often implemented in a subclass. So my wild guess for the implication is answer D.

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    The problem says:

    Class A extends Class B and B implements Interface C - what does it imply about the form of Class B?

    So let's change the statement slightly:

    class MyPanel extends JPanel and JPanel implements four interfaces.

    According to the teacher, that implies that the form of JPanel is abstract. But that would
    be an incorrect assumption since JPanel is not an abstract class.

    Regards,
    Jim
    Last edited by jim829; 04-29-2017 at 04:46 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  12. #12
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    I agree, there are more non-abstract classes that implement interfaces.

    Here I think that the originator wants to address this specific situation: abstract class implements interface and some interface methods are implemented in its subclasses. To me it sounds like a "did you listen in my class" question or a "did you read the homework" question (scroll all the way to the bottom). One can't really understand the question as sb not attending class. Overall I have seen better questions.
    Last edited by benji2505; 04-29-2017 at 05:03 AM.

  13. #13
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    This would be a better question that will actually work with the answers from the original question.
    class A extends class B and B implements interface C. Class A must implement some of the methods in interface C. What does that imply about class B?
    jim829 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  14. #14
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    And the logic would be, that implies B didn't implement all interface methods of C. But that is not allowed -- unless B is an abstract class.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  15. #15
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    Agreed! Especially to the "seen better questions statement."

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  16. #16
    misscoding is offline Member
    Join Date
    Apr 2017
    Posts
    4
    Rep Power
    0

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    Quote Originally Posted by jim829 View Post
    Agreed! Especially to the "seen better questions statement."

    Regards,
    Jim
    Thanks for your input guys!

    Yes, I'm attending all the classes! This is from the more academic lecturer. I prefer the lecturer who came from industry, he can say in 10 slides what would take the academic lecturer 50 slides to do!

    I've heard the questions have been submitted to a third party for review, so hopefully we don't get something like this in the exam!

  17. #17
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Class A extends B, and Class B implements Interface C - what is B? (Abstract, Lib

    If you are positive about your answer and it is marked as incorrect, or if your "academic" has other questions that just feel not right, please post them here including your reasoning. It's always nice food for discussion, and with the proper reasoning, you can even dispute your grade if it is unfairly marked incorrect. Just like the one you posted above.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Replies: 1
    Last Post: 07-09-2015, 08:22 AM
  2. Replies: 1
    Last Post: 07-08-2012, 05:23 PM
  3. Replies: 4
    Last Post: 01-17-2012, 12:39 AM
  4. Extends a class that implements an interface
    By monocole in forum New To Java
    Replies: 2
    Last Post: 12-27-2011, 03:55 AM
  5. Replies: 6
    Last Post: 02-11-2009, 10:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •