Your SlideShare is downloading. ×
0
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Methods and constructors in java
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Methods and constructors in java

712

Published on

Methods and constructors in java

Methods and constructors in java

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
712
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 2. Methods and constructors in java Shanu k k shanukk89@gmail.com www.facebook.com/shanunn i twitter.com/shanu in.linkedin.com/in/shanu k k 9656153432
  • 3. Typing Speed Week Target Achieved 1 25 25 2 27 30 3 35 29
  • 4. Jobs Applied # 1 2 3 Company Designation Applied Date Current Status
  • 5. Method oA Java method is a collection of statements that are grouped together to perform an operation o A class without method has no life,the object created by such class cannot respond to any message o Methods are declared inside the body of the class but immediately after the declaration of the instance variable
  • 6. Method declaration Type methodname(parameter_list) { Method_body; }
  • 7. Eg: Class rectangle { int length, width; Void getData(int x,int y) { Length=x; Width=y; } }
  • 8. class sum { void sum(int a,int b) { System.out.println( (a+b)); } void sum(int a,int b,int c) { System.out.println( (a+b+c)); } public static void main(String args[]) { sum obj=new sum(); obj.sum(10,5); obj.sum(10,5,10);
  • 9. Constructor: o Object we created must be given to instial values o We have done earlier using two approaches 1 2 Dot operator:access the instance variable and assign value them indiviidualy getData method:intialise each object individually
  • 10. it would be simpler to initialise an object when it’s first created _special type of method is called construcor • Constructor have the same name as the class itself • They do not specify any return type not even void
  • 11. • class Constructor Demo{ Constructor Demo(){ System.out.println("Inside no argument constructor"); } ConstructorDemo(String name){ System.out.println("Inside one argument constructor in Java with name: " + name); } public static void main(String args[]) { Constructor Demo d = new ConstructorDemo(); //calling no argument constructor in java Constructor Demo e = new ConstructorDemo("Testing"); //calling one argument constructor in java } }
  • 12. • Output: Inside no argument constructor Inside one argument constructor in Java with name: Testing •
  • 13. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 14. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550

×