Back to Browse

CONSTRUCTOR PART 2 IN JAVA in Hindi Lecture 52

7 views
May 6, 2026
8:33

//Java Default and Parameterized Constructor class example { int a,b; //default constructor example() { a=10; b=90; } //parameterized constructor example(int x,int y) { a=x; b=y; } void display() { System.out.println("a="+a); System.out.println("b="+b); } } class test { public static void main(String args[]) { example obj=new example(); obj.display(); example obj1=new example(30,40); obj1.display(); } } //Java Parameterized and Copy Constructor class example { int a,b; example(int x,int y) { System.out.println("parametrized constructor"); a=x; b=y; } //constructor to intilaize another object example(example obj) { System.out.println("copy constructor"); a=obj.a; b=obj.b; } void display() { System.out.println("a="+a); System.out.println("b="+b); } } class test1 { public static void main(String args[]) { example obj1=new example(10,20); obj1.display(); example obj2=new example(obj1); obj2.display(); example obj3=obj2; obj3.display(); } } //Java Constructor Overloading class example { int rno; String nm; int age; example(int i,String n) { rno=i; nm=n; } example(int i,String n,int a) { rno=i; nm=n; age=a; } void display() { System.out.println("rno="+rno); System.out.println("nm="+nm); System.out.println("age="+age); } } class test2 { public static void main(String args[]) { example obj=new example(101,"Tina Singh"); obj.display(); example obj1=new example(102,"Ram Singh",30); obj1.display(); } }

Download

1 formats

Video Formats

360pmp46.2 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

CONSTRUCTOR PART 2 IN JAVA in Hindi Lecture 52 | NatokHD