473,548 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheritance -- Implements,inte rface...

80 New Member
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...


Expand|Select|Wrap|Line Numbers
  1. class class1
  2.     {
  3.     public class1()
  4.     {
  5.     System.out.println("Class 1");
  6.     }
  7.     }
  8. interface class2
  9.     {
  10.     public void class2();
  11.     public void class3();
  12.     }
  13. class class3 implements class2
  14.     {
  15.     public class3()
  16.         {
  17.         System.out.println("Class 3");
  18.         }
  19.     public void class2()
  20.         {
  21.         System.out.println("Class 2");
  22.         }
  23.     }
  24. class class4 extends class1 implements class2
  25.     {
  26.     public class4()
  27.     {
  28.     System.out.println("Class 4");
  29.     }
  30.     public void class2()
  31.         {
  32.         System.out.println("Class 2");
  33.         }
  34. public static void main(String args[])
  35. {
  36. class4 c1=new class4();
  37. c1.class2();
  38. c1.class3();
  39. }
  40. }
  41.  
  42.  
Mar 22 '07 #1
4 1645
teddarr
143 New Member
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.
Mar 23 '07 #2
r035198x
13,262 MVP
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...


Expand|Select|Wrap|Line Numbers
  1. class class1
  2.     {
  3.     public class1()
  4.     {
  5.     System.out.println("Class 1");
  6.     }
  7.     }
  8. interface class2
  9.     {
  10.     public void class2();
  11.     public void class3();
  12.     }
  13. class class3 implements class2
  14.     {
  15.     public class3()
  16.         {
  17.         System.out.println("Class 3");
  18.         }
  19.     public void class2()
  20.         {
  21.         System.out.println("Class 2");
  22.         }
  23.     }
  24. class class4 extends class1 implements class2
  25.     {
  26.     public class4()
  27.     {
  28.     System.out.println("Class 4");
  29.     }
  30.     public void class2()
  31.         {
  32.         System.out.println("Class 2");
  33.         }
  34. public static void main(String args[])
  35. {
  36. class4 c1=new class4();
  37. c1.class2();
  38. c1.class3();
  39. }
  40. }
  41.  
  42.  
Java does not support multiple inheritance directly.
You cannot implement a class, you implement interfaces. Read this for clarification.
Mar 23 '07 #3
reon
80 New Member
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....
Mar 23 '07 #4
r035198x
13,262 MVP
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?
Mar 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
8368
by: Joe Delphi | last post by:
Does Visual Basic support multiple inheritance? That is one child class inheriting from more than one parent class. JD
4
8176
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by making my contnent dlls implement an interface created in vb6. The viewer application is bound to this interface. This way, I am able to add Content...
12
7022
by: Steve Jorgensen | last post by:
The classing Visual Basic and VBA support for polymorphism, let's face it, is a bit on the weak side, and built-in support for inheritance is non-existent. This little essay is about some patterns I've ended up using successfully for certain kinds of inheritance and polymorphism, and some that have not worked out so well. Let's start with...
22
23324
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
8
2198
by: Gaetan | last post by:
hi i have 2 classes A1 and A2 implementing a problem with 2 different ways i also have 2 other classes X1 and X2 implementing an other problem i need classes that provide A1+X1 methods, A1+X2, A2+X1 and A2+X2: interface A class A1 implements A
3
1425
by: Francois | last post by:
Hi, I am trying to extend a .NET class for overriding some methods. The class that I try to override is : System.Web.UI.WebControls.CheckBox. Its full definition is : public class CheckBox : WebControl, IPostBackDataHandler (notice the interface that is implemented) I want to override 3 methods belonging to that class:
9
1727
by: bob taylor | last post by:
Imagine I have two classes A and B. Class A has the function I, function J and Attribute K. Class B has the funcion X, function Y, Attribute Z. Is it possible to establish the following Class C through interitance: Class C which has the attribute K inherited from Class A and the attribute Z inherited from Class B ?
6
3799
by: Bart Simpson | last post by:
I remember reading on parashift recently, that "Composition is for code reuse, inheritance is for flexibility" see (http://www.parashift.com/c++-faq-lite/smalltalk.html#faq-30.4) This confused me somewhat as I have always thought you get code reuse "for free" with inheritance. Am I missing something?. Will someone care to explain ??
3
1299
by: =?Utf-8?B?UnVwZXJ0IFRheWxvcg==?= | last post by:
Hi This question is based around VB.Net but could probably apply to c# or any OOP language as well. We found some old (ish) code in our code base and have been unable to decide if it is pure genius or something else besides. As it stands we're leaning towards something else but would welcome some outside comments. The situation is.
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7803
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.