constructor

public class Stone {
int size;
float weight;
String colour;
// this is called instance variables beacuse property is specific for that instance
// this is a class


}

// what is a constructor
//method is same as a function...here stone is a function (method)
//constructor doesnot have a return type
//constroctor automatically gets invoked and assigns the same value in the callee
// here stone is a default constroctor
//eg:1stone(){
//abc
//}
//name of the constroctor must be same a class
// constructor with passing parameters
// eg2: stone(int size, int w, string colour){
//       this size =size;
  //  "no need of this"           weight=w;
//}      this colour=colour
// if we have multiple methods of same name with different arguments it is called overloading
// swapping the sequence also can be done
//but if we have two concecutive like.. int int then it doesnt allow overloading

class testStone
{
Stone granite=new Stone();
granite.size =100;
granite.weight=50;
granite.colour="grey";



}

Comments

Popular posts from this blog

commenting in java

Running a java program