9 Replies - 695 Views - Last Post: 19 June 2008 - 12:33 PM Rate Topic: -----

#1 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Multiple inheritence

Post icon  Posted 18 June 2008 - 11:51 AM

can any one help by giving an
example on interface concept of java on multiple inhertence
or any tuitorial

This post has been edited by prajayshetty: 18 June 2008 - 12:01 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Multiple inheritence

#2 jjsaw5  Icon User is offline

  • I must break you
  • member icon

Reputation: 90
  • View blog
  • Posts: 3,060
  • Joined: 04-January 08

Re: Multiple inheritence

Posted 18 June 2008 - 12:45 PM

View Postprajayshetty, on 18 Jun, 2008 - 02:51 PM, said:

can any one help by giving an
example on interface concept of java on multiple inhertence
or any tuitorial



have you tried googling this?

There are lots of tutorials here you could look at
Was This Post Helpful? 0
  • +
  • -

#3 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: Multiple inheritence

Posted 19 June 2008 - 10:06 AM

View Postjjsaw5, on 18 Jun, 2008 - 12:45 PM, said:

View Postprajayshetty, on 18 Jun, 2008 - 02:51 PM, said:

can any one help by giving an
example on interface concept of java on multiple inhertence
or any tuitorial



have you tried googling this?

There are lots of tutorials here you could look at

ya i always google before asking in this forum but i didnt got a good tuitroial on it
ne one hava good link for it actually i am not able to use multiple inheritence in java
in java support through interfaces but how

This post has been edited by prajayshetty: 19 June 2008 - 11:13 AM

Was This Post Helpful? 0
  • +
  • -

#4 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: Multiple inheritence

Posted 19 June 2008 - 11:45 AM

guys this is all what i know
import java.util.*;
import java.lang.*;
interface hello
{
	

	void getdata();
}
class c implements hello

{
	int c;
	
	public void getdata()
	{
		Scanner in = new Scanner(System.in);
	   System.out.println("enter a");
	   c=Integer.valueOf(in.nextLine());
	  
	}
public static void main(String args[])
{
	prajay p;
	c ca =null;
	d da =null;
   p=da;
   p.getdata();
   
}
}
class d implements hello
{
	int b;
	
	public void getdata()
	{
		Scanner in = new Scanner(System.in);
		System.out.println("enter b");
		c ca =null;
		prajay p;
		p=ca;
		p.getdata();
		
		b=Integer.valueOf(in.nextLine());
		
		d da = null;
		
		p=da;
		 p.getdata();
		 p=ca;
		 
		 
	}
}


i need to accesses a variable b of class d from class c is it possible can u gus plzz modify the code a bit is it possible if i put one more class called e and accesses all the three class variables through interface

This post has been edited by prajayshetty: 19 June 2008 - 11:48 AM

Was This Post Helpful? 0
  • +
  • -

#5 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: Multiple inheritence

Posted 19 June 2008 - 11:52 AM

guys delete this post sorry for that i had made some effort on mine side on the other post hope u guys help me there del this post

This post has been edited by prajayshetty: 19 June 2008 - 11:53 AM

Was This Post Helpful? 0
  • +
  • -

#6 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,476
  • Joined: 07-April 08

Re: Multiple inheritence

Posted 19 June 2008 - 11:56 AM

ok wow. I see alot of questionmarks coming in my head when i read this code.

let me start:

prajay p;
p=ca;



what is prajay? Is it another class that your initializing here? if so show me the code for that.


and basically to access the variable c inside class B from class C you would either initialize a new instance of class b like so
B b = new B();



then you can call the variable like so:

int c = b.b;




but i would highly recomend you go back over your code. give your classes better names, your variables better names.
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5322
  • View blog
  • Posts: 27,233
  • Joined: 10-May 07

Re: Multiple inheritence

Posted 19 June 2008 - 12:00 PM

** Topics merged **

Please reply to the original topic, rather than re starting a new one.
Was This Post Helpful? 0
  • +
  • -

#8 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,476
  • Joined: 07-April 08

Re: Multiple inheritence

Posted 19 June 2008 - 12:01 PM

exactly what i told them when they pmed me about this topic. Ohh and please do not send out pms to try and get help.
Was This Post Helpful? 0
  • +
  • -

#9 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: Multiple inheritence

Posted 19 June 2008 - 12:11 PM

ya there is no class prajay in it actually i modified the code later and forgotto remove that line
B)
here is the clear code
import java.util.*;
import java.lang.*;
interface hello
{
	

	void getdata();
}
class first implements hello

{
	int c;
	
	public void getdata()
	{
		Scanner in = new Scanner(System.in);
	   System.out.println("enter a");
	   c=Integer.valueOf(in.nextLine());
	  
	}
public static void main(String args[])
{
	hello p;
	first ca =null;
	second da =null;
   p=da;
   p.getdata();
  
}
}
class second implements hello
{
	int b;
	
	public void getdata()
	{
		Scanner in = new Scanner(System.in);
		System.out.println("enter b");
		first ca =null;
		hello p;
		p=ca;
		p.getdata();
		
		b=Integer.valueOf(in.nextLine());
		
		second da = null;
		
		p=da;
		 p.getdata();
		 p=ca;
		
		
	}
}


if i write something like this in void getdata() of class second for accessesing c of first this will it work
first c;
int d=0;
d=c.d;
System.out.println("d of class first =",+d);


This post has been edited by prajayshetty: 19 June 2008 - 12:25 PM

Was This Post Helpful? 0
  • +
  • -

#10 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,476
  • Joined: 07-April 08

Re: Multiple inheritence

Posted 19 June 2008 - 12:33 PM

just try doing this since you already initialize the other classes:


class second implements hello
{
    int b;
    
    public void getdata()
    {
        Scanner in = new Scanner(System.in);
        System.out.println("enter b");
        first ca = new first();
        hello p;
        p=ca;
        p.getdata();
        
        b=Integer.valueOf(in.nextLine());
        
        second da = null;// this line isnt needed.  Why create a new instance of the class your working in?
        int variablefromclassfirst = ca.c;
        p=da;
         p.getdata();
         p=ca;
        
        
    }
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1