You are on page 1of 7

//1.

program to print hello world java on console class Helloworld //class defintion { public static void main(String args[]) //entry point of jvm { System.out.println("hello world of java"); } }

// 2.wap to print sum of two number class value //class defintion { int num1,num2; //instance variable declaration int sum() //method of value class { int num3=num1+num2; //logic to sum of two number return num3; //return int type } } class Mainclass { public static void main(String args[]) //entry point of jvm { value obj=new value(); //object created obj.num1=11; //value assigned using object of that class obj.num2=15; int result; result=obj.sum(); //method invoke System.out.println("The sum of twom number : "+result); //output } }

// 3. Wap 3 to calculate circumference of circle class circ //class defintion { double rad; //instance variable declaration void circumference() //method { double result=2*3.14*rad; //local variable and logic to find circumference System.out.println("circumference of circle : "+result); //output } } class Circle { public static void main(String args[]) entry point of jvm { circ obj=new circ(); //object created obj.rad=3.6; // variable intialisation of radius obj.circumference(); //method invoke } }

// 4. wap to calculate volume of Box class value //class defintion { double length,width,height; //instance variable double volume() //method with return type { double vol=length*width*height; //logic to find volume of Box return vol; //to return value } } class Box { public static void main(String args[]) //entry point of jvm { value obj=new value(); //object created obj.length=2.1; //initalsation of instance variable through object obj.width=2.6; obj.height=4.7; double result=obj.volume(); //result catch System.out.println("volume of Box : "+result); //output } }

// 5 Wap for command line argument class Commandlinearg //class defintion { public static void main(String args[])//entry point of jvm { for(int i=0;i<args.length;i++) { System.out.println("The argument as follows with index " +i +": "+args[i]); //commnad line argument read } } }

// 6. wap for default constructor class Box { double height,width,depth; //instance variablee Box() //default constructor { height=2.4; //variable initalisation in default constructor width=1.5; depth=6.4; } double volume() //method { return (height*width*depth); } } class Defaultconsbox //class defintion { public static void main(String args[]) //entry point of jvm { Box obj=new Box(); //default invoke double result=obj.volume(); //method invoke System.out.println("volume of Box : "+result); } }

// 7 .wap for constructor overload class Circle //class defintion { double radius,rad; //instance variable Circle() //default constructor { radius=2.1; } Circle(double r) //parameteris constructor { rad=r; } void circumference() //method { double res1=2*3.14*radius; System.out.println("circumference of circle : "+res1); } void area() { double res2=3.14*rad*rad; System.out.println("area of circle : "+res2); } } class constover //class defintiton { public static void main(String args[]) //entry point of jvm { Circle obj=new Circle(); //default constructor invoke Circle obj1=new Circle(2.8); //parametris constructor invoke obj.circumference(); //method invoke obj1.area(); } }

You might also like