If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > i am a beginner in JAVA please help...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-19-08, 05:27
akuccputsedut akuccputsedut is offline
Registered User
 
Join Date: Jun 2007
Posts: 35
Red face i am a beginner in JAVA please help...

i'm 100% sure this is easy for you to treat where i'm wrong...but i'm the new beginner really don't know what happen...this code actually want to show a constructor in java...


this is the code


public class customer {

String name;
String address;
String discount;




customer() {}

customer c = new customer();


public static void main(String args[]) {



customer c1 = new customer("wan","ipoh");
customer c2 = new customer("nadia","kedah");
customer c3 = new customer("seri","penang");





System.out.println("name,address,discount");
}
}



don't know where the mistake i've done so many error...please help...
__________________
**akuccputsedut**
Intelligent is Me!!But a little confusing
sometimes needs HELP!!
Reply With Quote
  #2 (permalink)  
Old 06-19-08, 09:07
dimis2500 dimis2500 is offline
Registered User
 
Join Date: Jan 2005
Posts: 362
Code:
public class customer {
       	String name;
	String address;
	String discount;    

       customer() {}
	 customer(String Name,String Address) {
name=Name;
address=Address}          }
public class myclass
{public static void main(String args[]) {
	 customer c = new customer();
               customer c1 = new customer("wan","ipoh");
               customer c2 = new customer("nadia","kedah");
	       customer c3 = new customer("seri","penang");
		System.out.println("name,address,discount");
       }}
Try this
Reply With Quote
  #3 (permalink)  
Old 06-20-08, 03:43
akuccputsedut akuccputsedut is offline
Registered User
 
Join Date: Jun 2007
Posts: 35
thank you

thank's for your help but i still have error on print part..

system.out.println don't know why..???
__________________
**akuccputsedut**
Intelligent is Me!!But a little confusing
sometimes needs HELP!!
Reply With Quote
  #4 (permalink)  
Old 06-20-08, 05:20
pawarsunil pawarsunil is offline
Registered User
 
Join Date: Jun 2008
Posts: 4
Try below code.
U have two constructor one without any arguments and one with two arguments name and surname.
run and check output

package com.test;
public class customer {

String name;
String address;
String discount;




customer() {
System.out.print("Inside No argument Constructor");
}

public customer(String name, String surname) {
// TODO Auto-generated constructor stub
System.out.print("Passed parametrs are Name "+name+" Surname" +surname);
}




public static void main(String args[]) {


customer c = new customer();
customer c1 = new customer("wan","ipoh");
customer c2 = new customer("nadia","kedah");
customer c3 = new customer("seri","penang");





System.out.println("name,address,discount");
}
}
Reply With Quote
  #5 (permalink)  
Old 06-20-08, 10:03
dimis2500 dimis2500 is offline
Registered User
 
Join Date: Jan 2005
Posts: 362
Quote:
Originally Posted by dimis2500
Code:
public class customer {
       	String name;
	String address;
	String discount;    

       customer() {}
	 customer(String Name,String Address) {
name=Name;
address=Address}          }
public class myclass
{public static void main(String args[]) {
	 customer c = new customer();
               customer c1 = new customer("wan","ipoh");
               customer c2 = new customer("nadia","kedah");
	       customer c3 = new customer("seri","penang");
		System.out.println("name,address,discount");
       }}
Try this
]
Code:
public class customer {
       	String name;
	String address;
	String discount;    
public String getname()
{return name;}
public String getaddress()
{return address;}
       customer() {}
	 customer(String Name,String Address) {
name=Name;
address=Address}          }
public class myclass
{public static void main(String args[]) {
	 customer c = new customer();
               customer c1 = new customer("wan","ipoh");
               customer c2 = new customer("nadia","kedah");
	       customer c3 = new customer("seri","penang");
		System.out.println("name"+c1.getname()+",address"+c1.getaddress());
       }}
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On