Saturday, 26 August 2023

OOPS

Class and Object: Spaciman blank form is class and filled form by taking its photocopy   by multiple students is  object 















Inheritance: You can use your mobile and your father's mobile also but your father can not use your mobile. 

your fathers property is yours , but your property is not your fathers



Method OverRiding:  Parent and Child class having the function with the same name. 

Parent-Child relationship + Riding






Method OverLoading : 

Example 1 : You and your son are going to start dinner. You asked for spoon. Knowing that you want to serve rice  from kadhai to plate son will give you a big spoon. if you are going to start eating from your plate he will give you small spoon.  



Example 2 : In the same class there are draw( a,b) , draw(a,b,c) , draw( a,b,c,d) . First funcion will draw a line, second will draw a triangle and the third will draw a rectangle.  


static block: is like a bulb inside the fridge which gets switched ON automatically just before you open the fridge door. When the class is loaded static block gets executed at first 


Encapsulation:   public setter and getter methods  and private variables  in one capsule



Constructor: Whenever the doorbell rings, the door gets opened by the house owner. Whenever an object is created constructor gets executed. 





The house owner's name is the same as written on the nameplate. The constructor name is the same as the class name. 

// Class name: Student

public class Student{

// Constructor has always the same name as the class

public Student() {

System.out.println("Constructor is called!");

}


public static void main(String[] args) {

// Creating an object, which will invoke the constructor

Student obj = new Student();

}

}







How to read this : 

 List<Integer> rollNumbers  = List.of(101, 109, 125, 107);

above code should be read as 

List of Integer called rollNumbers. here 

<   can be  spoken as of

>  can be spoken as  called 


How to read this : 

for ( int i : arr) 
    System.out.println(i);
}

above code should be read as 

for each integer i in array. here 
( can be spoken as for 
: can be spoken as in 



How to use this in for loop
Answer: when we start from zero we have to keep  less than the array length only

public static void main(String[] args) {

int[] arr = {1, 2, 3, 4, 5};

System.out.println(arr.length);

for( int i= 0; i <arr.length; i++)

{

System.out.print (arr[i]);

}

}



How to say this : (Collection::stream)

Answer: Turn all these collections of lists into a single stream of individual elements

No comments:

Post a Comment