Java/C2/Default-constructor/Gujarati
From Script | Spoken-Tutorial
Revision as of 12:23, 2 September 2013 by Jyotisolanki (Talk | contribs)
Time' | Narration |
00:02 | જાવામાં default constructor પરનાં સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે. |
00:07 | આ ટ્યુટોરીયલમાં આપણે શીખીશું |
00:10 | default constructor વિશે. |
00:12 | અને constructor ને બનાવવું. |
00:15 | અહીં આપણે વાપરી રહ્યા છીએ
ઉબુન્ટુ આવૃત્તિ ૧૧.૧૦ જાવા ડેવલપમેંટ એન્વાયર્નમેંટ જેડીકે ૧.૬ અને એક્લીપ્સ ૩.૭.૦ |
00:26 | આ ટ્યુટોરીયલનાં અનુસરણ માટે તમને જાણ હોવી જરૂરી છે કે |
00:29 | જાવામાં કેવી રીતે એક્લીપ્સની મદદથી ક્લાસ અને ક્લાસનું ઓબ્જેક્ટ બનાવવું.
|
00:34 | જો નથી, તો સંદર્ભિત ટ્યુટોરીયલો માટે બતાવ્યા મુજબ અમારી વેબસાઈટ જુઓ,
(http://www.spoken-tutorial.org)
|
00:42 | Constructor દ્રષ્ટાંત વેરીએબલોને પ્રારંભ કરવા માટે વપરાય છે. |
00:46 | તેને નવું ઓબ્જેક્ટ બનાવતી વખતે કોલ કરવામાં આવે છે. |
00:50 | ચાલો હવે જોઈએ જાવામાં constructor ને કેવી રીતે વ્યાખ્યાયિત કરવું. |
00:55 | તો એક્લીપ્સમાં, મેં પહેલાથી જ જાવા ફાઈલ, Student.java બનાવી છે. |
01:02 | Student ક્લાસમાં આપણે બે વેરીએબલો જાહેર કરીશું.
|
01:07 | તો ટાઈપ કરો int roll_number અર્ધવિરામ અને String name અર્ધવિરામ. |
01:20 | Now let us create a method. |
01:22 | So type void studentDetail() |
01:33 | Within curly brackets type System dot out dot println roll_number |
01:50 | Then System dot out dot println name |
02:03 | Now in Main method we will call this method. |
02:08 | So let us create an object and call the method.
|
02:14 | So type Student object name stu equal to new Student |
02:28 | Then stu dot method name i.estudentDetail |
02:41 | Save and Run the program. |
02:46 | We see the output zero and null. |
02:49 | So, the int variable roll_number has been initialized to its default value zero. |
02:56 | And the String name has been initialized to its default value null.
|
03:02 | If we do not define a constructor then a default constructor is created.
|
03:08 | Default constructor has no parameters. |
03:11 | It initializes the instance variables to their default value.
|
03:16 | Now let us define a constructor. |
03:18 | So type Student parenthesis and curly brackets.
|
03:30 | Remember the Constructor has the same name as the class name to which it belongs.
|
03:38 | Constructors are also similar to methods but there are some important differences. |
03:44 | Save and Run the program. |
03:48 | We see the same output. |
03:51 | This is because the constructor, that we defined is same as having no constructor. |
03:58 | But here no default constructor is created because we have defined a constructor. |
04:06 | Now lets give values to our variables. |
04:11 | So inside the constructor type roll_number equal to ten semicolon. |
04:25 | And name equal to within double quotes Raman |
04:35 | Now Save and Run the program. |
04:43 | We see in the output that the roll_number value is ten and name is Raman. |
04:50 | So the constructor initializes the instance field. |
04:55 | Now let us see some difference between method and a constructor. |
05:01 | Constructor does not have a return type. |
05:05 | Whereas Method has a return type. |
05:10 | Constructor is called using the new operator. |
05:16 | Whereas the Method is called using the dot operator. |
05:21 | So this were some differences between constructor and method. |
05:29 | So in this tutorial, we have learnt |
05:32 | About the default constructor. |
05:34 | To define a contructor. |
05:36 | And Differences between method and constructor.
|
05:41 | For self assessment, |
05:42 | Create a class Employee with variables and a method to display variables. |
05:47 | And Create a constructor for the class Employee. |
05:52 | To know more about the Spoken Tutorial Project |
05:54 | Watch the video available at http://spoken-tutorial.org/What_is_a_Spoken_Tutorial |
06:00 | It summarizes the Spoken Tutorial project |
06:03 | If you do not have good bandwidth, you can download and watch it
|
06:06 | The Spoken Tutorial Project Team |
06:08 | Conducts workshops using spoken tutorials |
06:11 | Gives certificates to those who pass an online test |
06:14 | For more details, please write to contact@spoken-tutorial.org |
06:20 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
06:24 | It is supported by the National Mission on Education through ICT, MHRD, Government of India |
06:29 | More information on this Mission is available at
http://spoken-tutorial.org/NMEICT-Intro
|
06:38 | This brings us tothe end of the tutorial. |
06:40 | Thanks for joining. |
06:42 | This is Prathamesh Salunke signing off. Jai Hind. |