Class & Object: =============== class: ======= ==> a category of one or more than one object by sharing different properties (data (attribute) and functionality (method)). ==> a blueprint of one or more than one object by sharing different properties. ==> collection of attributes(data) and methods (behavior/functionality). class Student{ int stuid; String stuname; String stubatch; int marks; void display() { sop(id); } } Object: ======= ==> Any thing/everything in the real world is called as an "object". ==> Instance of the class. stu1{ id = 1; name = "Neeraj" batch = "73-jsfd marks = 88 } Employee Student Customer e1 = "abc", 50k, SDE e2 = "xyz", 75k, SSDE ==================================================== Creation of the class: ====================== ==> to create the class in java: we can use "class" keyword. Syntax: class name_of_the_class{ } ==> we can create the class above the main class and below to the package name. ==> class is the logical entity, for this definition the JVM never reserve any memory. ================================================= Creation of Object: =================== ==> to create the object, "new" operator (keyword). Ex: Scanner obj = new Scanner(System.in); // for scanner object creation Syntax: className reference-name/object-name = new className(); Here: className ==> for which class we are creating object reference-name ==> Object name new ==> keyword, which helps to allocate the memory for the object in JVM Heap. className() ==> Constructor can use to initialize the object. ==> Object we should create always in main(). ==> Suppose, we have created a class and created an object for that class without assignment of data/values then: the object can store in heap memory with default values according to the data type of attributes of the class. =========================================== How to assign values for object: ================================ package AshokIT.OOPs; class Employee{ int empid; String empname; double salary; void display() { System.out.println("Employee Id = "+empid); System.out.println("Employee Name = "+empname); System.out.println("EMployee Salary = "+salary); } } public class MainClass { public static void main(String[] args) { // creating the object for the given class Employee emp1 = new Employee(); System.out.println(emp1.empid); // 0 System.out.println(emp1.empname); // null System.out.println(emp1.salary); // 0.0 emp1.empid = 79697; emp1.empname = "Kundana Sri"; emp1.salary = 67000.00; System.out.println(emp1.empid); // 0 System.out.println(emp1.empname); // null System.out.println(emp1.salary); // 0.0 emp1.display(); System.out.println("================================="); Employee emp2 = new Employee(); emp2.empid = 79799; emp2.empname = "Krishna"; emp2.salary = 56000.00; emp2.display(); } } ==================================================== Assignment: =========== Q: WAP TO CREATE THE CLASS "Player" WITH ATTRIBUTES pid, pname, prank, pbatch AND CREATE A METHOD TO DISPLAY THE PLAYER DATA. ==================================================== Q:1) ==== class Class1{ } class Class2{ } public class Class3{ public static void main(String[] args) { } } what is the file name? class3.java ==> the IDE can search the class which is with "public" that class name only the name of the java file. ========================= Q:2) class Class1{ } class Class2{ } public class Class3{ } public class Class4{ public static void main(String[] args) { } } what is the file name? Ans: Error, because no java file with more than one Public class.