Sunday, January 31, 2016

TestConstructor

package Constructor;

public class TestConstructor {

int a;
int b;


TestConstructor() {
System.out.println("I am from parent default constructor");
}

TestConstructor(int a){
this.a = a;
System.out.println("I am from parent parameterized constructor");
}


TestConstructor(int a,int b){
this.a = a;
this.b = b;
}
void display(){
System.out.println("value of a is:-"+a);
}

void sum(){
int c = a+b;

System.out.println("sum of two number is :-"+c);
}
public static void main(String[] args) {
// TODO Auto-generated method stub

TestConstructor obj = new TestConstructor();

obj.display();
TestConstructor obj1 = new TestConstructor(5);

obj1.display();

TestConstructor obj2 = new TestConstructor(5,10);

obj2.sum();
}

}

1 comment:

  1. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    Java Training in Electronic city

    ReplyDelete