| |
Welcome to the dBforums forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact support.
If you prefer not to see double-underlined words and corresponding ads, place your cursor here for ContentLink opt out.
|
 |

06-19-08, 06:27
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 32
|
|
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!!
|
|

06-19-08, 10:07
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 337
|
|
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
|
|

06-20-08, 04:43
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 32
|
|
|
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!!
|
|

06-20-08, 06:20
|
|
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");
}
}
|
|

06-20-08, 11:03
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 337
|
|
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());
}}
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|