
Course Contents of Java OOP Basics that can be covered in 2 Hrs time frame by Udemy fro Free courses
Object oriented programming is a programming concept based on the concept of objects.
The main aim of the OOP is to bind data and functions together.
Object Oriented Programming has advantages over other programming concepts like Procedure Oriented Programming (POP).
Java is an object oriented programming language.
OOP provides many concepts such as encapsulation, inheritance, abstraction, polymorphism etc.
OOP is mainly based on Class & Objects.
Class:
As per Object Oriented Analysis and Design (OOAD) many definitions are given for a class; in that two well known definitions are :
1) Class is a Concept
2) Class is a blue-print
Object:
An object is a real instance or living instance of a class.
This means that an object is created from the definition of the class and is loaded in heap memory.
Any number of objects can be created for a class
Each object has its own memory space that can hold independent data values.
An object consists of :
1) State : represents each data (value) of an object.
2) Behavior : represents the functionality of an object such as deposit(), withdraw() etc in a banking application.
3) Identity : the unique ID of an object. It is used internally by the JVM to identify each object uniquely.
Constructors
A Constructor is a special type of method in a class
The name of the constructor method is same as that of the class name
Constructor method should not have an explicit return type.
A constructor is used for initalizing the member datas of an object
A Constructor method will be executed automatically whenever an object of a class is created
When an object is created, atleast one constructor gets executed
Constructors are of two types: (a) Default Constructor - compiler defined constructor (b) Parameterized Constructor
The compiler will create a construtor at the time of compilation, only if there is no user defined constructors are available in the class definition
Difference between constructor and a normal method of a java class
1) Constructor is used to initialize the state of an object.
Method is used to expose behaviour (business logic) of an object.
2) Constructor must not have explicit return type.
Method must have return type.
3) Constructor is executed implicitly when an object of a class is created.
Method should be called explicitly, then only it will gets executed.
4) The java compiler provides a default constructor if there is no constructor defined in the class.
A normal Method is not created by compiler in any case.
5) Constructor name must be same as the class name.
Method name may or may not be same as class name.
Overloading Methods
In a class if there exists more than one method with the same name but with different signatures are known as overloading methods or method overloading
The name of the method together with parameter details is known as method signature
The method calling signature should be matching with method definition signature
In a class it is not possible to have more than one method with the same signature
There are two ways to overload the method in java
1) By changing number of arguments
void add(int x, int y){ }
void add(int x, int y, int z){ }
2) By changing the data type of arguments
void add(int x, int y){ }
void add(int x, float y){ }
In a class if there exists more than one constructor with different signatures is known as overloading constructors.
"this" Keyword
"this" is a keyword of Java acting as the reference to the current object inside a Java class method.
"this" keyword can be used to access current class method and instance variables
"this" keyword can be used to access current class constructor,and is called as constructor chaining.
Call to this() must be the first statement in constructor if constructor chaining is required.
"this" keyword can be passed as an argument in the method call.
"this" keyword can be used to return the current class instance.
etc
Inheritance is the process of creating a new concept from an already existing concept(s).
The process by which one class acquires the properties(data members) and functionalities(methods) of another class is called inheritance.
Why do we use inheritance?
Since some common properties and methods are required by few classes hence they have to be implemented in all those classes.
To avoid code redundancy, a class is developed with the common attributes and methods and it is used as a base class for the derived classes
Where do we use inheritance?
Inheritance can be used in all place where parental properties and methods are used.
Inheritance represents the IS-A relationship, also known as parent-child relationship.
Inheritance is introduced for code reusability.
Keywords Used:
extends
implements
Overriding Members
When a method in a child class has same name, same number of arguments and same types as a method in its super class, then the method is known as overridden method.
The benefit of overriding method is the abitility to define method that is specific to a particular child class type.
The same member datas present in the super class and also in the child class is known as overriding member datas.
When a child class object calls a method, it will always refer to the method defined by the child class. The method defined by the super class will be hidden.
Rules for Java Method Overriding
method must have same name in child class as in the super class
method must have same parameters ( parameter number and parameter type) as in the super class.
must be IS-A relationship (inheritance).
This course is designed to give you the real understanding of Object Oriented Programming in Java Programming Language. By the end of this 02 Hrs course, you will understand Object Oriented Programming in Java extremely well. You will get to know know about the role of OOP in application development, getting the actual concepts of Class, Object, Constructors, Overloading methods, Overloading Constructors, use of "this" keyword, Inheritance, Overriding members and the use of "super" keyword. You will study the OOP by implementing a simple Banking Application