Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Example,

Java
class loan{
       private String name;
       private String id;
       private String address; 
//.. ... ..
// ... ... ..
//... ... ...

}


class librarian{
private String name;
private String id;
private String address;

public loan input_loan{
// .. .
//... ... ...
//... ... ...

return l1;

}
}


Not in main but in two different class without inheritance?
please if you have solution do it here.
Posted
Updated 30-Oct-11 11:59am
v2
Comments
Sergey Alexandrovich Kryukov 30-Oct-11 23:55pm    
Why would you ever repeat name, id, address?! As soon as you repeat anything, this is a sure sign of a flaw. Use loan instead.
--SA

1 solution

Not 100% sure this is what you're asking, but it looks like you're having trouble instantiating a new loan object from within a method of the librarian class so you can return the loan object from the method?

If so, the piece you're missing is this:

Java
loan l1 = new loan();


After you instantiate the loan with that code, you can then call setters on the loan (you have those I trust?) to initialize the loan.

Note that if the librarian and loan classes are in different packages, you will need to import the package containing the loan class in librarian.java!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900