SlideShare ist ein Scribd-Unternehmen logo
1 von 27
new operator and methods




                           http://improvejava.   1
                           blogspot.in/
Objective


On completion of this period, you would be able to know

          • new operator
          • Methods




                            http://improvejava.b          2
                            logspot.in/
Recap

Class :
   •   is blue print or plan of an object
   • class consists both methods and instance variables
   • syntax of class declaration :
               class class_name {
                        instance variables;
                        methods;
               }
Object :
               is an instance of a class

                                                          3
                            http://improvejava.               3
                            blogspot.in/
new Operator

• You know how to declare a primitive variable and assign              it a
  value
             eg. : int x = 10;
• What about non-primitive variables? i.e. what about objects?
• When you create a class, you are creating a new data type
syntax of class declaration :                Example :
class class-name {                           class Student {
  instance variables;                          int sno, m1, m2, m3;
  methods;                                     void total_mks() {….}
}                                            }


• You can use class to declare objects of that type
                                                                              4
                                  http://improvejava.                             4
                                  blogspot.in/
new operator
•    Creating objects of a class is a two-
     step process
Step 1
•    Declare a variable of the class type.
                                                     null
•       eg. : Student s;
                                                      s
Step 2
•    Allot the required memory and                                       sno
                                                      s
     initialize its data members                                         m1
•    You can do this using the ‘new’                                     m2
     operator                                                            m3
•        eg. s = new Student();                                   Student object

                                                     Fig. 14.1 Creating object
                               http://improvejava.                               5
                               blogspot.in/
Use of new Operator

• The new operator dynamically allocates memory for an object
  and returns a reference to it

• This reference is the address in memory of the object allocated
 by new. This reference is stored in the variable



• Thus, in Java all objects will be dynamically allocated



                             http://improvejava.                    6
                             blogspot.in/
Another Way Of Creating Object
• In the preceding example,
               Student s;                   // declares a reference to object
               s = new Student();           // allocates a Student object

• By combining above two statements ,we can also write
       Student s = new Student(); // this is same as above

• Object reference is similar to pointers, but the difference is you
cannot manipulate references as you can do with pointers




                               http://improvejava.                              7
                               blogspot.in/
Closer Look At ‘new’

• ‘new’ operator dynamically allocates memory for an object
• The general form of it is
      ClassName objVar = new ClassName();
• here, objVar is a variable of the class type being created

• ClassName is the name of the class that is being instantiated

• ClassName followed by parenthesis ‘( ) ‘ specifies the constructor

   of the class

                              http://improvejava.                      8
                              blogspot.in/
Advantages Of ‘new’

• Program can create as many or as few objects as it needs
  during the execution of your program

   • No memory wastage


   • No insufficient memory message (unless total
     memory is used )



                        http://improvejava.              9
                        blogspot.in/
Introduction To Methods

• Classes   usually consisting of two things
   • Instance variables
   • Methods
• Instance variables : these are the variables declared inside
a class
   eg.:      class A {
                 int x; // x is an instance variable
             }
                              http://improvejava.            10
                              blogspot.in/
Introduction To Methods
• Methods are functions declared in a class
• A method will perform a specified task related to the
class
   eg. : class A {
            int x; // x is an instance variable
             void display( ) {//display is a method to print value of      x
                     System.out.println(“value of x is”+x);
              }
         }


                      http://improvejava.blogspot.in/            11
                                                                      11
                              9CM604.15
General Form Of A Method
The general form of a method
        type method-name([parameter-list]) {

            // body of method

         } // end of method


        eg. :
          int add(int x, int y)) {
                    int res;
                    res = x + y;
                    return(res);
           } // end of method




                                     http://improvejava.   12
                                     blogspot.in/
General Form Of A Method                  contd..


• A method should return a value
• The type of value returned is called ‘return type’ of the method
• If the method does not return a value, its return type must be void
• Name of the method must be a legal identifier
• Parameter-list is a sequence of type and identifier pairs separated by
 commas
• Parameters are essentially variables that receive the value of the
arguments passed to the method when it is called

                              http://improvejava.                       13
                              blogspot.in/
General Form Of A Method                    contd..


•If the method has no parameter, then the parameter list will be
empty


• Method that have a return type other than void return a value to the
calling routine using the following form of the return statement
                      return x;
   Here, ‘x’ is the value returned


                             http://improvejava.                         14
                             blogspot.in/
Adding A Method To Class
• Methods to do specified task are defined by the class
   eg. :
       class Student {
         int sno, m1, m2, m3;
         void total_mks() {
                int total_mks;
                total_mks = m1 + m2 + m3;
       System.out.println(“total marks of the student”+total-mks);
          }// end of method
         } // end of class
   • total_mks() is a method
   • Its task is to find the total of m1,m2 and m3
                             http://improvejava.                     15
                             blogspot.in/
Calling A Method


class UseStudent {
   public static void main(String args[]) {
        Student s = new Student();
       s.m1 = 99; s.m2 = 80; s.m3 = 35;
        s.total_mks();
   }// end of method
 } // end of class



                         http://improvejava.   16
                         blogspot.in/
Calling A Method                    contd..
• Look closely at the following line             Dot operator is used
                                                 to access methods in
     s.total_mks();                              class



• The above statement invokes the total_mks() method
  on ‘s’

  i.e it calls total_mks() relative to the ‘s’ object,
  using the object name followed by the dot(.) operator


                                                                        17
                          http://improvejava.b
                          logspot.in/
Calling A Method                          contd..

• When we call s.total_mks() JVM transfers control to
  the code defined inside the class
• After execution of the above method, control return
  back to the calling routine




                  http://improvejava.blogspot.in/             18
                                 9CM604.15
Calling A Method               contd..

• A method is always invoked relative to some object
  of its class
• Thus, within a method, there is no need to specify the
  object a second time




                         http://improvejava.b              19
                         logspot.in/
Discussion
• Classify Methods based on return type and parameter
  passing
   •   Methods that have no return type, no parameters
   •   Methods that have no return type, but have parameters
   •   Methods that have return type, but no parameters
   •   Methods that have both return type, parameters




                      http://improvejava.blogspot.in/          20
                                     9CM604.15                      20
Summary
In this class, you have learnt
• ‘new’ operator
• Usage of new operator
• Methods




                   http://improvejava.blogspot.in/   21
                                  9CM604.15               21
Quiz

1. Objects memory is created
   a. statically
   b. dynamically
   c. none




                                            22
                      http://improvejava.        22
                      blogspot.in/
Quiz                       contd..

2. What is new?
   a. operator
   b. method
   c. variable
   d. none




                  http://improvejava.blogspot.in/             23
                                                                   23
                          9CM604.15
Quiz                   contd..

3. What is reference?
    a. variable
   b. kind of pointer
   c. object
   d. none




                                                         24
                         http://improvejava.                  24
                         blogspot.in/
Quiz                           contd..

4 . What operator is used to access
    a. @
    b. ^
    c. *
    d. .(dot)




                    http://improvejava.blogspot.in/             25
                                                                     25
                            9CM604.15
Frequently Asked Questions



   Explain the syntax of a method
   What is .(dot) operator? What is the use of it?
   Explain the mechanism of invoking a method in
    Java?




                                                      26
                      http://improvejava.                  26
                      blogspot.in/
Assignment
1. Write a class called Student consisting of
     pin_no, sname, fname, city as instance variables,
     get_stu_details and disp_stu_details as methods
   Create an object for the above class, and access both
   methods to do the above operations
2. Write a class called Employee consisting of
     eno, ename, desgination, tot_salary as instance
   variables, get_emp_details and disp_emp_details as
   methods. Create an object for the above class, and
   access both methods to do the above operations

                        http://improvejava.                27
                        blogspot.in/

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Multiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptxMultiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptx
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
 
This and Static Keyword
This and Static KeywordThis and Static Keyword
This and Static Keyword
 
Java arrays
Java arraysJava arrays
Java arrays
 
OOP java
OOP javaOOP java
OOP java
 
Trigger
TriggerTrigger
Trigger
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
interface in c#
interface in c#interface in c#
interface in c#
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Inheritance
InheritanceInheritance
Inheritance
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 

Andere mochten auch

Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operationsarchikabhatia
 
Template at c++
Template at c++Template at c++
Template at c++Lusain Kim
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cppgourav kottawar
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureRai University
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.pptTareq Hasan
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++gourav kottawar
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 

Andere mochten auch (20)

Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
 
Operators
OperatorsOperators
Operators
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
 
Template at c++
Template at c++Template at c++
Template at c++
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Managing console
Managing consoleManaging console
Managing console
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
C++ Template
C++ TemplateC++ Template
C++ Template
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 

Ähnlich wie b. dynamically2. Methods are declared inside a. class b. object

Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in javaElizabeth alexander
 
Java As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsJava As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsHelen SagayaRaj
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructorsJan Niño Acierto
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptxEpsiba1
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in javaagorolabs
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptxakila m
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaRadhika Talaviya
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxShaownRoy1
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesSakkaravarthiS1
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
chapter 5 concepts of object oriented programming
chapter 5 concepts of object oriented programmingchapter 5 concepts of object oriented programming
chapter 5 concepts of object oriented programmingWondimuBantihun1
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
 

Ähnlich wie b. dynamically2. Methods are declared inside a. class b. object (20)

Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
Java As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsJava As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & Applets
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
 
6 Object Oriented Programming
6 Object Oriented Programming6 Object Oriented Programming
6 Object Oriented Programming
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
chapter 5 concepts of object oriented programming
chapter 5 concepts of object oriented programmingchapter 5 concepts of object oriented programming
chapter 5 concepts of object oriented programming
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
 
Java defining classes
Java defining classes Java defining classes
Java defining classes
 
Constructors and Method Overloading
Constructors and Method OverloadingConstructors and Method Overloading
Constructors and Method Overloading
 

Mehr von myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

b. dynamically2. Methods are declared inside a. class b. object

  • 1. new operator and methods http://improvejava. 1 blogspot.in/
  • 2. Objective On completion of this period, you would be able to know • new operator • Methods http://improvejava.b 2 logspot.in/
  • 3. Recap Class : • is blue print or plan of an object • class consists both methods and instance variables • syntax of class declaration : class class_name { instance variables; methods; } Object : is an instance of a class 3 http://improvejava. 3 blogspot.in/
  • 4. new Operator • You know how to declare a primitive variable and assign it a value eg. : int x = 10; • What about non-primitive variables? i.e. what about objects? • When you create a class, you are creating a new data type syntax of class declaration : Example : class class-name { class Student { instance variables; int sno, m1, m2, m3; methods; void total_mks() {….} } } • You can use class to declare objects of that type 4 http://improvejava. 4 blogspot.in/
  • 5. new operator • Creating objects of a class is a two- step process Step 1 • Declare a variable of the class type. null • eg. : Student s; s Step 2 • Allot the required memory and sno s initialize its data members m1 • You can do this using the ‘new’ m2 operator m3 • eg. s = new Student(); Student object Fig. 14.1 Creating object http://improvejava. 5 blogspot.in/
  • 6. Use of new Operator • The new operator dynamically allocates memory for an object and returns a reference to it • This reference is the address in memory of the object allocated by new. This reference is stored in the variable • Thus, in Java all objects will be dynamically allocated http://improvejava. 6 blogspot.in/
  • 7. Another Way Of Creating Object • In the preceding example, Student s; // declares a reference to object s = new Student(); // allocates a Student object • By combining above two statements ,we can also write Student s = new Student(); // this is same as above • Object reference is similar to pointers, but the difference is you cannot manipulate references as you can do with pointers http://improvejava. 7 blogspot.in/
  • 8. Closer Look At ‘new’ • ‘new’ operator dynamically allocates memory for an object • The general form of it is ClassName objVar = new ClassName(); • here, objVar is a variable of the class type being created • ClassName is the name of the class that is being instantiated • ClassName followed by parenthesis ‘( ) ‘ specifies the constructor of the class http://improvejava. 8 blogspot.in/
  • 9. Advantages Of ‘new’ • Program can create as many or as few objects as it needs during the execution of your program • No memory wastage • No insufficient memory message (unless total memory is used ) http://improvejava. 9 blogspot.in/
  • 10. Introduction To Methods • Classes usually consisting of two things • Instance variables • Methods • Instance variables : these are the variables declared inside a class eg.: class A { int x; // x is an instance variable } http://improvejava. 10 blogspot.in/
  • 11. Introduction To Methods • Methods are functions declared in a class • A method will perform a specified task related to the class eg. : class A { int x; // x is an instance variable void display( ) {//display is a method to print value of x System.out.println(“value of x is”+x); } } http://improvejava.blogspot.in/ 11 11 9CM604.15
  • 12. General Form Of A Method The general form of a method type method-name([parameter-list]) { // body of method } // end of method eg. : int add(int x, int y)) { int res; res = x + y; return(res); } // end of method http://improvejava. 12 blogspot.in/
  • 13. General Form Of A Method contd.. • A method should return a value • The type of value returned is called ‘return type’ of the method • If the method does not return a value, its return type must be void • Name of the method must be a legal identifier • Parameter-list is a sequence of type and identifier pairs separated by commas • Parameters are essentially variables that receive the value of the arguments passed to the method when it is called http://improvejava. 13 blogspot.in/
  • 14. General Form Of A Method contd.. •If the method has no parameter, then the parameter list will be empty • Method that have a return type other than void return a value to the calling routine using the following form of the return statement return x; Here, ‘x’ is the value returned http://improvejava. 14 blogspot.in/
  • 15. Adding A Method To Class • Methods to do specified task are defined by the class eg. : class Student { int sno, m1, m2, m3; void total_mks() { int total_mks; total_mks = m1 + m2 + m3; System.out.println(“total marks of the student”+total-mks); }// end of method } // end of class • total_mks() is a method • Its task is to find the total of m1,m2 and m3 http://improvejava. 15 blogspot.in/
  • 16. Calling A Method class UseStudent { public static void main(String args[]) { Student s = new Student(); s.m1 = 99; s.m2 = 80; s.m3 = 35; s.total_mks(); }// end of method } // end of class http://improvejava. 16 blogspot.in/
  • 17. Calling A Method contd.. • Look closely at the following line Dot operator is used to access methods in s.total_mks(); class • The above statement invokes the total_mks() method on ‘s’ i.e it calls total_mks() relative to the ‘s’ object, using the object name followed by the dot(.) operator 17 http://improvejava.b logspot.in/
  • 18. Calling A Method contd.. • When we call s.total_mks() JVM transfers control to the code defined inside the class • After execution of the above method, control return back to the calling routine http://improvejava.blogspot.in/ 18 9CM604.15
  • 19. Calling A Method contd.. • A method is always invoked relative to some object of its class • Thus, within a method, there is no need to specify the object a second time http://improvejava.b 19 logspot.in/
  • 20. Discussion • Classify Methods based on return type and parameter passing • Methods that have no return type, no parameters • Methods that have no return type, but have parameters • Methods that have return type, but no parameters • Methods that have both return type, parameters http://improvejava.blogspot.in/ 20 9CM604.15 20
  • 21. Summary In this class, you have learnt • ‘new’ operator • Usage of new operator • Methods http://improvejava.blogspot.in/ 21 9CM604.15 21
  • 22. Quiz 1. Objects memory is created a. statically b. dynamically c. none 22 http://improvejava. 22 blogspot.in/
  • 23. Quiz contd.. 2. What is new? a. operator b. method c. variable d. none http://improvejava.blogspot.in/ 23 23 9CM604.15
  • 24. Quiz contd.. 3. What is reference? a. variable b. kind of pointer c. object d. none 24 http://improvejava. 24 blogspot.in/
  • 25. Quiz contd.. 4 . What operator is used to access a. @ b. ^ c. * d. .(dot) http://improvejava.blogspot.in/ 25 25 9CM604.15
  • 26. Frequently Asked Questions  Explain the syntax of a method  What is .(dot) operator? What is the use of it?  Explain the mechanism of invoking a method in Java? 26 http://improvejava. 26 blogspot.in/
  • 27. Assignment 1. Write a class called Student consisting of pin_no, sname, fname, city as instance variables, get_stu_details and disp_stu_details as methods Create an object for the above class, and access both methods to do the above operations 2. Write a class called Employee consisting of eno, ename, desgination, tot_salary as instance variables, get_emp_details and disp_emp_details as methods. Create an object for the above class, and access both methods to do the above operations http://improvejava. 27 blogspot.in/