00:00
/*01 - Obj. init. With user value */
class Employee{
int emp_id;
}
public class J02 {
public static void main (String[] args){
Employee e = new Employee ();
e.emp_id=101;
System.out.println(e.emp_id); //101
}
}
// this is not the safe way
/*02 - Obj. init. With gtr./str. */
class Employee{
private int emp_id; // called data hiding
public void set_info(int a){
emp_id = a;
}
public int get_info(){
return emp_id;
}
}
public class J02 {
public static void main (String[] args){
Employee e = new Employee ();
e.set_info(101);
System.out.println(e.get_info());
}
}
//101
/*03 - Obj.init. With gtr/str + same var. */
class Employee{
private int i;
public void set_i(int i){
i = i; // both local variables
}
public int get_i(){
return i; // instance variables
}
}
public class J02 {
public static void main (String[] args){
Employee e = new Employee ();
e.set_i(1231);
System.out.println(e.get_i());
}
}
// 0
/*04 - obj. init. With gtr/str + same var.+this*/
class Employee{
private int i;
public void set_i(int i){
this.i = i;
}
public int get_i(){
return i;
}
}
public class J02 {
public static void main (String[] args){
Employee e = new Employee ();
e.set_i(1231);
System.out.println("this is the working of this keyword "+e.get_i());
}
}
// this is the working of this keyword 1231
/*05 - This:invoke current cls. mt().*/
public class J02 {
void display(){
System.out.println ("hello");
}
void show (){
display (); // complier = this.display();
this.display();
}
public static void main (String[] args){
J02 td=new J02();
td.show () ;
}
}
// hello
// hello
/*06 - This:invoke current cls ct().*/
public class J02 {
J02(){
System.out.println ("No Arguments c/t ");
}
J02(int a, int b ){
System.out.println ("Two Parameterized c/t ");
}
J02(int a ){
this(); // call no argumenent c/t, coz it has no arg.
System.out.println ("Parameterized c/t ");
}
public static void main (String[] args){
J02 td1 = new J02(10);
}
}
// No Arguments c/t
// Parameterized c/t
/*07 - This(int a) : invoke current cls ct().*/
public class J10 {
J10(){
this(10); // call int argumenent c/t
System.out.println ("No Arguments c/t ");
}
J10(int a ){
System.out.println ("Parameterized c/t ");
}
public static void main (String[] args){
J10 td1 = new J10();
}
}
// Parameterized c/t
// No Arguments c/t
/*08 - This:pass as an argument in mt call*/
public class J11 {
void m1 (J11 td){ // parameters
System.out.println ("No Arguments c/t ");
}
void m2 (){
m1(this); // argumnets
}
public static void main (String[] args){
J11 td1 = new J11();
td1.m2();
}
}
// No Arguments c/t
/*09 - This: pass as an argument in ct call*/
class Book{
Book(J12 td){
System.out.println("book");
}
}
class J12 {
void m1 (){
Book t = new Book(this);
}
public static void main (String[] args){
J12 t = new J12();
t.m1();
}
}
// book
/*10 - This:return current cls. Instance form mt. */
class J14 {
J14 m1 (){ // jab bhee esa likah ho , uska matlab hai m1 instance hai class ka
return this;
}
public static void main (String[] args){
J14 t = new J14();
t.m1();
}
}
/*11 - Super:reference var., immediate pt. Cls. var */
public class J15 {
int i = 10;//2
}
class b extends J15{
int i = 20;//1
void show(int i){
System.out.println(i);
System.out.println(this.i);//1
System.out.println(super.i);//2
}
public static void main(String[] args) {
b ob = new b();
ob.show(30);
}
}
// 30
// 20
// 10
/*12 - Super:immediate pt. Cls. mt(). */
class A {
void m1(){
System.out.println("i am in class A");
}
}
class J17 extends A{
void m1(){
System.out.println("i am in class B");
}
void show(){
super.m1();
m1();
}
public static void main(String[] args) {
J17 ob = new J17();
ob.show();
}
}
// i am in class A
// i am in class B
/*13 - Super:immediate pt. cls.ct(). */
class A {
A(){
System.out.println("i am in class A");
}
}
class J18 extends A{
J18(){
super(); // compiler add this automatically
System.out.println("i am in class B");
}
public static void main(String[] args) {
J18 ob = new J18();
}
}
// i am in class A
// i am in class B