Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
constuctor concept
ppavya india
Greenhorn
Posts: 19
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all,
I am new to
java
technology. Could anyone explain me the concept of contructor, its use, with appropriate example.
Thanx in advance.
Arnaud Burlet
Ranch Hand
Posts: 31
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Constructors are not only a concept of the java technology, this is a concept of Object Oriented Programming (OOP).
Do you need an intro to OOP ? or just an intro of how it works in java ?
class test { int i; // this is the constructor // it is called when new object of class test are created before anyone can use that object // we can perform initialisation tasks in the constructor public test() { System.out.println("Initializing a new test object"); // do more init stuffs here i = 23; } // you can pass arguments to constructors public test(int i) { System.out.println("Initializing a new test object with i set to : " + i); this.i = i; } static void main( String[] args) { // when we create a object of type test, the constructor is called test test1 = new test(); test test2 = new test(12); } }
[edit : basic corrections]
[ October 14, 2004: Message edited by: Arnaud Burlet ]
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
what is a isolation level,is it a concept in EJB or a RDBMS concept?
java servlets extending jpanel
classpath in ruby
session that never dies
Regarding Tx and Security Context for Interceptor method
More...