Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Simple question about a small program

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Simple question about a small program

    Hello java members this is my first post as u can see so i have been confused with this small part of code.Its a question i got to answer from school.Here is the part of code

    interface Interface1 { }
    interface Interface2 {}
    interface Interface3 extends Interface2{ }

    class Class1 implements Interface1 { }
    class Class2 implements Interface3 { }
    class Class3 extends Class2{ }

    Class1 a = new Class1(); Class2 b = new Class2(); Class3 c = new Class3();

    Which of the following expressions is correct?

    1. Class1 instanceof Interface2
    2. Class2 instanceof Interface3
    3. Class2 instanceof Interface2
    4. Class3 instanceof Interface2

    And if someone can explain me with some words witch one is correct and why? i would apriciate it very much thanks for your time mates!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,271
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Simple question about a small program

    Can you post what you think are the answers and the reason why?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Simple question about a small program

    Quote Originally Posted by Norm View Post
    Can you post what you think are the answers and the reason why?
    I bilieve only the 4) is true cause interface 3 extends interface 2 ;/ not 100% sure...

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,271
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Simple question about a small program

    Try writing a small program that uses instanceof to test which statements are true.
    For example:
            String str = "ss";
            System.out.println(str instanceof String);
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    azizmaiden (March 2nd, 2013)

  6. #5
    Junior Member Robertgif's Avatar
    Join Date
    Feb 2013
    Posts
    19
    My Mood
    Amazed
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Simple question about a small program

    If it helps, look at each possible answer and backtrack it through the code. Working backwards might help you from getting confused.
    "You should not let technology (or method) drive your design, but make your design drive the technology".

    Always learning!

  7. The Following User Says Thank You to Robertgif For This Useful Post:

    azizmaiden (March 2nd, 2013)

  8. #6
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Simple question about a small program

    thanks guys solved!

Similar Threads

  1. A very simple question...
    By jhy2a in forum Java Theory & Questions
    Replies: 2
    Last Post: April 6th, 2012, 11:18 PM
  2. Game for Small Children Program
    By Javazoid in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 29th, 2012, 04:02 PM
  3. Simple I/O Question...well could be simple for you?
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 30th, 2011, 07:44 AM
  4. urgent simple help for a very simple program
    By albukhari87 in forum Java Applets
    Replies: 4
    Last Post: June 5th, 2010, 04:43 PM
  5. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 03:47 AM