Inheritance -- Implements,interface...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reon
    New Member
    • Feb 2007
    • 80

    #1

    Inheritance -- Implements,interface...

    Hi

    In this program i tried implements,inhe ritance (I tried multiple inheritance in C++).
    In C++ I knew that multiple inheritance means we can invoke all classes and class functions from derived class itself with an object...
    I tied that same idea in Java , but in java it is a flop to me...
    I tried inheritance using implements and interface in java...

    If anybody having any idea or know how can repair this code please tell me...
    Now also i think that i can directly call outer class methods from derived class of java with an object...


    Code:
    class class1
    	{
    	public class1()
    	{
    	System.out.println("Class 1");
    	}
    	}
    interface class2
    	{
    	public void class2();
    	public void class3();
    	}
    class class3 implements class2
    	{
    	public class3()
    		{
    		System.out.println("Class 3");
    		}
    	public void class2()
    		{
    		System.out.println("Class 2");
    		}
    	}
    class class4 extends class1 implements class2
    	{
    	public class4()
    	{
    	System.out.println("Class 4");
    	}
    	public void class2()
    		{
    		System.out.println("Class 2");
    		}
    public static void main(String args[])
    {
    class4 c1=new class4();
    c1.class2();
    c1.class3();
    }
    }
  • teddarr
    New Member
    • Oct 2006
    • 143

    #2
    I'm a newb to Java, but one thing I do know is that unlike C++, Java does not allow multiple inheritance.

    My only reference is that I am taking both classes this semester and the instructor pointed out this exact situation.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by reon
      Hi

      In this program i tried implements,inhe ritance (I tried multiple inheritance in C++).
      In C++ I knew that multiple inheritance means we can invoke all classes and class functions from derived class itself with an object...
      I tied that same idea in Java , but in java it is a flop to me...
      I tried inheritance using implements and interface in java...

      If anybody having any idea or know how can repair this code please tell me...
      Now also i think that i can directly call outer class methods from derived class of java with an object...


      Code:
      class class1
      	{
      	public class1()
      	{
      	System.out.println("Class 1");
      	}
      	}
      interface class2
      	{
      	public void class2();
      	public void class3();
      	}
      class class3 implements class2
      	{
      	public class3()
      		{
      		System.out.println("Class 3");
      		}
      	public void class2()
      		{
      		System.out.println("Class 2");
      		}
      	}
      class class4 extends class1 implements class2
      	{
      	public class4()
      	{
      	System.out.println("Class 4");
      	}
      	public void class2()
      		{
      		System.out.println("Class 2");
      		}
      public static void main(String args[])
      {
      class4 c1=new class4();
      c1.class2();
      c1.class3();
      }
      }
      Java does not support multiple inheritance directly.
      You cannot implement a class, you implement interfaces. Read this for clarification.

      Comment

      • reon
        New Member
        • Feb 2007
        • 80

        #4
        then anybody please tell me wats the use of implements and interface in java...
        If java does not suppot multiple inheritance ...

        Then how can i complete the task like this ; i mean multiple inheritance....

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by reon
          then anybody please tell me wats the use of implements and interface in java...
          If java does not suppot multiple inheritance ...

          Then how can i complete the task like this ; i mean multiple inheritance....
          Have you read the link that I gave you?

          Comment

          Working...