DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    10

    Constructors , paprameters and super

    When i instantiate an object with parameters " SubClient clientobjecttest = new SubClient(fsname,lsname,tphone,adss); "
    my code kicks out the following error


    C:\J2SDK1~1.2_0\BIN>javac reportprogram.java
    reportprogram.java:169: cannot resolve symbol
    symbol : constructor SubClient (java.lang.String,java.lang.String,int,java.lang
    .String)
    location: class SubClient
    SubClient clientobjecttest = new SubClient(fsname,lsname,tphone,adss);

    ^

    Thing is, if I don’t include the parameters, it compiles ok, so I suspect I need to use super so I inserted it by where it says problem 1 in the code.

    Still I have this problem. Please could you help.




    Code:
    class Person{
    
    
    	void Person(String fsname,String lsname,int tphone,String adss) {
    	
    	
    	
    	}
    
    	// as of this moment i am unsure of how data will getinto these variable possile by the use of super
    	String firstname;
    	String lastname;
    	String address;
    	int telephonenumber;
    }
    
    
    class SubClient extends Person {
    
    
    	//creating a constructor to get variables ,because i dont seem to be able to the the class to exten as well as 
    	//take parameters.
    	
    		void SubClient(String fsname,String lsname,int tphone,String adss) {
    
    		super(fsname,lsname,tphone,adss);	 			// PROBLEM 1		
    			String testvalue = "test";
    			super.firstname = fsname;
    			super.lastname = lsname;
    			super.telephonenumber =tphone;		
    			super.address = adss;
    			System.out.println(testvalue);
    			// the line above is only for test
    		
    		
    		}
    	
    		void printclientdetails() {
    			
    		}
    		
    	
    
    }	
    
    
    class reportprogram {
    	public static void main(String args[])throws IOException{
    
    	// thes variables for testing	
    	String destina	 = "paris";
    	String flightno 	= " ch102";
    	int    noofcargo	= 4;
    	char   cargoclass	= 'd';
    			
    
    //PROBLEM 2
    //SubClient clientobjecttest = new SubClient(fsname,lsname,tphone,adss);	
    	
    PROBLEM 3
    SubClient clientobjecttest = new SubClient();	
    	
    	
    
    
    	}

  2. #2
    Join Date
    Jan 2004
    Posts
    8
    I have prepared the following code that sorts out your problem. For a good series of tutorials on OOP with Java go to http://www.developer.com/java/article.php/935351

    This has a full series of tutorials written by **** baldwin
    The full series is also available at www.dickbaldwin.com

    Here is the code I sorted out for you

    class Person
    {
    String firstName;
    String lastName;
    String address;
    int telephoneNumber;

    Person(String fsname,String lsname,int tphone,String adss)
    {
    firstName = fsname;
    lastName = lsname;
    telephoneNumber = tphone;
    address = adss;
    }
    }





    class SubClient extends Person
    {
    //creating a constructor to get variables ,because i dont seem to be able to the the class to exten as well as
    //take parameters.

    SubClient(String fsname,String lsname,int tphone,String adss)
    {
    super(fsname,lsname,tphone,adss); // PROBLEM 1
    String testvalue = "test";
    System.out.println(testvalue);
    // the line above is only for test
    }

    void printClientDetails()
    {
    System.out.println (firstName);
    System.out.println (lastName);
    System.out.println (telephoneNumber);
    System.out.println (address);
    }
    }




    class PersonDriver
    {
    public static void main(String args[])
    {

    // these variables for testing
    String first = "Ashley";
    String last = "Hulme";
    int tel = 12345678;
    String adds = "England";


    //PROBLEM 2
    SubClient clientObjectTest = new SubClient(first,last,tel,adds);
    clientObjectTest.printClientDetails();

    //PROBLEM 3
    //SubClient clientobjecttest = new SubClient();
    //To use the default constructor you would have to insert setter methods into the sub class
    }
    }


    hope this helps

    Ash
    ashley.hu1me@virgin.net
    dont hesitate to contact me if you have any more problems
    Attached Files

  3. #3
    Join Date
    Jan 2004
    Posts
    10

    Thankyou

    Your reply has been a great deal of help thankyou

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links