this() in constructor
-The this() call in a constructor invokes the an other constructor with the corresponding parameter list within the same class.
-Java requires that any this() call must occur as the first statement in a constructor.
program:public class Cube2 {
int length;
int breadth;
int height;
public int getVolume() {
return (length * breadth * height);
}
Cube2() { this(10, 10);
System.out.println("Finished with Default Constructor");
}
Cube2(int l, int b) { this(l, b, 10);
System.out.println("Finished with Parameterized...
Saturday, 30 June 2012
Constructor in JAVA
05:58
No comments
Constructor in JAVA
-Constructor initialize an object Of a class immediately upon creation.
-JAVA creates constructor call for every object that is created.
-When you create a new instance (a new object) of a class using the new keyword, a constructor for that class is called.
program 1:public class contest { contest()
{
System.out.print("this is constructor");
}
public static void main(String[] a) {
constortest c=new constortest();
}
}
output:this is constructor
-Constructors are similar to methods, but with some important...
Method Overloading in JAVA
05:49
No comments
Method Overloading in JAVA-Methods of same name can be declared in java in the same class,they have different set of parameters(number ,types,order of parameters).
-When an overloaded method method is called,JAVA compiler identify the appropiate method by using the parameters and it types,numbers and order of the arguments.
program:public class methodoverload { public static void main(String[] a) {
int i=123; int j=13;
double d=13.9;
func();
func(i);
func(i,d);
func(d,i);
func(59,4,"gkads");
}
public static void...
Pass by Reference in java
05:42
No comments
Pass by Reference in java
-Passing the address or sending the copy of reference.
-If any changes in copied method ,it affect the original method.
-Pass By Reference is based on the object of a class or a object like
int[] a=new int[10]; program:public class passarray {
public static void main(String[] a)
{
int[] array={1,2,3,4,5};
System.out.println("effect of passing reference to entire array:\n"+"the value of the original array are:");
for(int...
public static void main(String[] a) in JAVA
05:06
3 comments
public static void main(String[] a)Why we are declaring "public static void main(String[] a)" in JAVA programs.What is the purpose of declaring like this.program:public class test1 { public static void main(String[] a)
{
System.out.print("java main function");
}
}output:java main functionpublic -(access control:public) allows everyone can access this method. ...
Subscribe to:
Posts (Atom)