Upcoming SlideShare
Loading in...5




Hariprasanna V (9843824677)

Hariprasanna V (9843824677)



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • nice
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

1 1 Presentation Transcript

  • Day 4
    • Introduction to:
    • Classes & Objects
    • Methods
    • Constructors
    • Garbage Collections
  • 2 Classes & Objects
    • Classes are collecton of objects
    • Thus, a class is template for an object, and an object is an instance of a class.
    • A class is declared by use of the class keyword. The general form of a class is :
    • class classname {
    • type instance-variable1;
    • type instance-variable2;
    • //….
    • type methodname1(parameter-list) {
    • //body of method
    • }
    • //…
    • type methodnameN(parametere-list) {
    • //body of method}}
  • .
    • Declaring Objects : Obtaining objects of a class is a two-step process. First u must declare a variable of the class type. This variable does not define an object. Second, you must acquire an actual, physical copy of the
    • object ans assign to that variable. You can do this by using the new operator.
    • Box mybox = new Box();
    • The new operator dynamically allocates memory for an object. It has the general form:
    • Class-var = new classname();
    • Object Reference Variables.
    • Box b1 = new Box();
    • b2 = b1;
    • Introducing Methods : The general form the method is:
    • type name(parameter-list){
    • // body of the method
    • }
    • Methods that have a return type other than void return a value to the calling routine using the following form of the return statement:
    • return value;
    • here, the value is the value returned.
    • Adding a method to the Box class (e.g. refer codes)
    • Returning a Value (e.g. refer codes)
    • Adding a Method that takes Parameters (e.g. refer codes )
    • Constructors : Java allows object to initialize themselves when they are created. This automatic initialization is performed through the use of the constructors.
    • A constructors initialization an objects immediately upon creation. It has the same name as the class in which it resides and is syntactically similar to the method. Once defined, the constructor is automatically called immediately after the object is created, before the new operator completes.( e.g. refer codes)
    • Parameterized Constructors
    • This keyword : this can be used in any method to refer to the current object. This is always a reference to an object on which the method is invoked.
    • Garbage Collection
    • Overloading Methods
    • Overloading Constructors
    • Using Objects as Parameters.
    • Argument Passing : call-by-value & call-by-Reference.
    • Returning Objects.
    • Recursion.
    • static.
    • final.
    • Arrays Revisited (method to find the length of array)
    • Nested classes & Inner Classes.
    • Command-Line-Arguments.
  • Sample Code class BoxDemo { public static void main(String args[]) { Box mybox = new Box(); double vol; // assign values to mybox's instance variables mybox.width = 10; mybox.height = 20; mybox.depth = 15; // compute volume of box vol = mybox.width * mybox.height * mybox.depth; System.out.println("Volume is " + vol); } }