Created
August 19, 2020 05:11
-
-
Save neer2808/6bcb0f6577718f0ab31849721f78dd2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Constructor123 { | |
int rollno; // instance variable | |
String name; | |
Constructor123 () | |
{ | |
rollno = 10; | |
name = "ABC"; | |
} | |
Constructor123(String str) | |
{ | |
name = str; | |
rollno = 0; | |
} | |
public void m1() | |
{ | |
System.out.println(rollno + " " + name); | |
} | |
public static void main(String[] args) { | |
Constructor123 obj = new Constructor123(); | |
obj.m1(); | |
Constructor123 obj1 = new Constructor123("qqq"); | |
obj1.m1(); | |
} | |
} | |
// overloading | |
// by providing the different no of arguments | |
// Constructor123(int ) | |
// Constructor123( int, int) | |
// Constructor123( int, int, int ) | |
// by providing different types of arguments | |
// Constructor123 ( int) | |
// Constructor123( char) | |
// Constructor123(String); | |
// Constructor123(int,String) | |
// Constructor123(String, int) | |
// this super and this() super() | |
// this and super are keywords in java | |
// this is used to refer current class instance members | |
// super is used to refer to the super class instance members | |
// this() and super() by using these we can make constructor calls | |
// super() it is used to call super class constructor | |
// this() it is used to call current class constructor | |
//inheritance , overloading and overriding | |
//inheritance and overriding concepts are not applicable for constructor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment