Results 1 to 3 of 3
  1. #1
    dawnMist is offline Member
    Join Date
    Oct 2012
    Posts
    43
    Rep Power
    0

    Default 2 interfaces and their methods

    Hello,

    so I have been working on another class assignment and I found a problem.

    I have 2 interfaces declared:

    Java Code:
    public interface Measurable {
        double getWidth();
    
        double getHeight();
    
        double getLength();    
    }
    Java Code:
    public interface Solid extends Measurable {
        double getArea();
    }
    Now I use a this class to write some info on std. output:

    Java Code:
    public class Gauger
    {
        public static void printMeasurement(Measurable msr) {
            System.out.println(msr.toString());
            System.out.println("Perimeter: " + msr.getLength());
        }
        
        public static void printMeasurement(Solid sld) {
    
        }
    }
    and I want to use the second printMeasurement method to do exactly the same as the first one, without copying the source code.
    My guess is I have to use my interfaces, I just ainīt sure how.
    I would be grateful for any help and hints, thanks.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: 2 interfaces and their methods

    Java Code:
        public static void printMeasurement(Solid sld) {
        	printMeasurement((Measurable)sld);
        	System.out.println("Area: "+sld.getArea());
        }
    ?? ??

  3. #3
    dawnMist is offline Member
    Join Date
    Oct 2012
    Posts
    43
    Rep Power
    0

    Default Re: 2 interfaces and their methods

    Quote Originally Posted by eRaaaa View Post
    Java Code:
        public static void printMeasurement(Solid sld) {
        	printMeasurement((Measurable)sld);
        	System.out.println("Area: "+sld.getArea());
        }
    ?? ??
    That was it, now I get it, thank you so much.

Similar Threads

  1. Replies: 2
    Last Post: 07-12-2012, 11:04 PM
  2. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  3. Java Noob, trying to call methods from another methods
    By gabrielpr12 in forum New To Java
    Replies: 8
    Last Post: 11-17-2011, 09:07 PM
  4. Replies: 10
    Last Post: 10-28-2011, 09:12 PM
  5. Replies: 1
    Last Post: 10-05-2011, 12:15 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
  •