What Is An Automation?
Automation Testing:-
- It is Process through which quality of an application can be
guaranteed by using code to perform an action automatically
over an application without intervention of user
What do you mean by automation?
Need of Automation:-
- Repetitive Task which should be perform at all the stages
requires an Automation
- To ensure the quality within Less Amount of Time
- To Reduce Human Efforts and Errors Caused by an individual
- To ensure the quality on Different browser at same time(Cross
Browser Testing)
- Operating System bases testing can also be achieved
- Report which tells us about execution of an application can be
prepared easily
When we try to develop code/Script using any language we
require following tools
- Work Area (Where we write code) //Notepad
- Compiler (High level language to low level language) // java
compiler
- Execution Area (Where we execute/run the our program )
//Cmd Promt //Powershell
Solution to this time consuming problem is – IDE
IDE – Integrated Development Environment
It is an integrated tool where we can
- Write a code
- We can compile code
- We can Execute in the same
IDE-
IDE is bridge between user and operating system through which we
can write code, compile it and execute the code in the same tool
Example:-
Eclipse, Intellij, Visual Basic, Android studio etc.
Why we are mostly using an Eclipse?
- It is an open source software (We do not have to pay for this
software)
- It is simple user interface which is easily understandable
- Compatible with Mac, Windows as well as Linux/Unix
- Auto format source code allows customization and increase
readability
- It reports an error automatically to the line and on which word
it has occurred
- It does good job presenting different programming languages
i.e. java, C#, Ruby, Pearl, Python, Groovy etc.
Which IDE you are using in your current organization?
What is an IDE?
Why most of organization using Eclipse as an IDE?
--------- We are going to learn JAVA--------
Why?
Slogan – “JAVA is Everywhere” – Write once and Run Anywhere
For Web Base Application the most popular and easy tool we are
going to use for an automation is Selenium
Java + Selenium + Eclipse = Automation tools
Feature Of Java:-
- Simple And Platform Independent Language
- Object Oriented Language
- Secure
- Portability ( repetitive things can be addressed easily in JAVA )
- Multithreading ( On the same time multiple program can be
accessed )
- Garbage Collector
(unused memory storage which is present in an Object can be
easily identified and can be released using Garbage Collection
feature)
The finalize() is static method which is present in Object Class
which get called for garbage collection
- where this method identifies unused object means there
should not be any further reference available to the given
object , then this method will consider that object for garbage
collection and destroy it
(In 1991 JAVA was developed by Sun Microsystem later it was taken
by Oracle, JAVA name is based on one of breed of coffee)
Flavors of JAVA :-
1. JAVA SE (Core JAVA) – Standard Edition – Basic
2. JAVA EE (Advance JAVA) – Enterprise Edition – Server/Backend
Related application
3. JAVA ME(Micro Edition) – Mobile Bases Application
Architecture of JAVA:-
JAVA Program Architecture:-
Package:-
- Package is nothing but the collection of all different classes
which consist of logics for performing project execution
Class:-
- Class is collection of objects , Variables and Methods
- Class is plan through which we come to know about different
logics we are having on our program
- Object Class is parent class of all classes present in JAVA
Object:-
- Object is combination of state and behavior of java program
- Object is a physical representation of memory where we are
going to perform a task in java
- Object is nothing but the instance of class
Example:-
Variable:-
- Variable is container which holds the value while execution of
java program
- It is a state of Java program
Method:-
- Class consist of various logics and logic can be define through
methods
- It is Behavior of Java Program
Data:-
- Data is nothing but the information provided by user in terms
of values
It could be numeric, Alphanumeric and special Char
Example :
20 – numeric, 20.20 – Numeric
Ab125Cd – Alphanumeric Data
A – Character
Data Types
Question:-
Do you think JAVA is an Object Oriented Language?
- Yes (We can addressed the memory in form of objects which
provides instance of class for execution and storage)
Is JAVA fully Object Oriented Language?
Do you think JAVA is 100% Object Oriented Language?
Why Java is not fully Object Oriented Language?
- Because it accepts primitive data type directly where object is
not required to accept the data
- It allows static memory allocation where we can execute the
program
That’s why java is not fully or 100% Object Oriented
Primitive Data Type Non Primitive Data Type
Primitive data type is structure that Non primitive data type is structure
stores data of only one type which is that can store data of either one type
defined on under particular data type or it could be different type under one
data type
e.g. int a = 20; it will always have any e.g. String a = “av18$#5t”;
numeric value within range of int
int[] a = {12,55,44,88};
String[]b = {Avdhut, Velocity, JAVA};
Primitive data type does not required Non primitive data type requires an
an Object to store or accept data Object to accept the data , and this
data can be fetched by calling that
object
The size(Range) depends on the type The size of Non primitive data type is
of data we are using and it is fixed for not fixed and it will be decided when
particular data type actual data gets stored inside an
(byte, short ,int etc..) Object
It starts with lower case charchter It starts with upper case char
Ex:- Ex.
int a = 20; String a = “avdhut”
byte b = 20;
short c = 20;
char d = ‘@’;
boolean = true;
Example : int , short , byte ,char etc. Example :-
String , array
Numeric Data Type:-
Byte- (1 byte, 8 bit)
If sign bit contains 0 (+ve)
If sign bit contains 1 (-ve)
Sign
0 1 1 1 1 1 1 1
Maximum No. allowed in 1 Byte
(2^7)-1 = +127(decimal)
Sign
1 0 0 0 0 0 0 0
Minimum No. allowed in 1 Byte
(2^7) = -128 (decimal)
Range of Byte -128 to 127
Short- (2 byte , 16bit)
Max. No allowed in short:-
(2^15)-1 = 32767
Min. No allowed in short:-
(2^15) = - 32768
Range of Short: -32768 to 32767
Int – (4 byte, 32bit)
Max. No allowed in short:-
(2^31)-1 = +2147483647
Min. No allowed in short:-
(2^31) = -2147483648
Range of Short: -2147483648 to +2147483647
Long- (8byte, 64bit)
Max. No allowed in short:-
(2^63)-1 = 9223372036854775807
Min. No allowed in short:-
(2^63) = - 9223372036854775808
Range of Short: - 9223372036854775808 to
+9223372036854775807
With Decimal:
Float- (4 byte, 32bit)
Minimum to maximum of float
(-3.4 10^38 to 3.4*10^38)
Double- (8 bye, 64bit)
Minimum to maximum of Double
(-3.4 10^308 to 3.4*10^308)
Non Numeric
Char- (2byte)
- All ASC2 values and symbols are applicable
- Symbols(!@#$%& etc.) are allowed
ASC2 + Symbols = Unicode
Example:-
We can conclude char can accept Unicode;
At time only one char or special char is allowed
Boolean:-
- No specific Bytes allocated
- It works on bit level
- Bit contains 1 – true
- bit contains 0 – false
Example:-
Primitive Data Types
Methods:-
- Class consist of various logics and logics can be define through
methods
- Methods are set of code which represents logic that can be
called number of time whenever required
- To represent logic or behavior in java we required method
Types Of method:-
1. Main method
2. Regular Methods (Static method and Non static)
Main Method-
Syntax:
public static void main(String[] args){
}
- Method which get executed by JVM once programmer run the
program in particular sequence
- Main method acts and worked exactly like static method
Example:
Output:
Regular Methods: (Static Method)
Static Method:-
- Static methods are class level methods where object creation is
not required
- i.e. they get loaded at the time of class loading
- To call static method inside main method in the same class we
can call directly by method name
Example:
Output:
Non static method:-
- These methods are object dependent methods where object
creation mandatory
- Memory allocation will be done once non static method gets
call
- Memory deallocation takes place immediately after execution
of method
- To call non static method inside main method in the same
class we can call by using an Object of that class
Example:
How to create an Object?
ClassName A = new ClassName();
//this is how object can be created
How to call non static method ?
[Link]();
Difference between Static and Non Static method:
Sr. Static method Non static method
no
1. Static method are class level Non static method are object level
method methods
2. It can be accessible directly inside It can be accessible in main
the main method(if it is defined in method using object
same class)
3. Memory allocation takes place at Memory allocation takes place at
the time of class loading and de- the time of method execution and
allocation of memory takes place once method execution gets
at the time of class unloading completed it get deallocated
4. It is recommended only when we It is recommended only when we
are sure of its usage are not sure to execute the task
continuously
5. Syntax Syntax
public static void public void m1() {
m1() {
}
}
Calling static method inside another static method
Calling non static method inside another Non static method
Calling static method inside another Non static method
Calling Non static method inside another static method
Variable:-
- Variable is container which holds the value while execution of
JAVA program
Variable Types:-
Global Variable –
- Static Variable
- Non static variable (Instantaneous Variable )
Local Variable
Example:
Global Variable
Static Variable:-
- It is class level defined variable
- It can be accessed throughout the class
- Object creation is not required
- Only define at class level with static keyword
- Cannot be defined on method level
- Static variable get memory allocated at the time of class
loading and memory get deallocated at the time of class
unloading
Non static Variable:-
- Define at class level
- But can be accessed through only an Object
- Scope of non-static variable is same as scope of given object
- To call non static variable inside main method object creation is
mandatory
- Non static variables values can be changed from object to
object
Ex.
- If we do not assigned any value to the non-static variable or
static variable JVM will assigned default value
Ex.
Default values:
- Byte =0;
- Short =0;
- Int =0;
- Long =0
- Float = 0.0;
- Double = 0.0;
- Boolean = false;
- Char = ‘ ’; (Null)
Local Variables:
- Local variable are such variable which defines within methods
or constructor
- Scope of local variable would be within the curly bracket only
- JVM does not provide default value to the local variable,
Initialization is must in Local Variable
- If name of Non static variable is same as Local Variable then to
access Non static Variable inside Non static method we should
use “this” keyword
(Only for Non Static Method)
Example:
- If name of Static variable is same as Local Variable then to
access static variable inside method we should use
“[Link]”
(Only for static variable)
Example:-
- To call only local variable inside method we can call directly (In
any type of method but within method)
Summary of Variables:-
[Link] Static Variable NonStatic Local Variable
Variable
1 Define on class Define on Class Define inside
level level Methods/Constructor
2 Access Access Access only inside
throughout throughout the Methods/Constructor
the class object
3 “this” keyword “this” keyword This keyword is used
is not used is not used when name of local
variable is same as non-
static variable
4 JVM will assign JVM will assign JVM will not assign
default values default values if default value ,
if not not initialized Initialization is must
initialized
5 Object Object creation Object creation not
creation not required required
required
6 Value of static Value of Non Value of local variable
variable static variable remains same
remains same can be changed throughout the method
throughout from object to
the class object
7 Memory Memory Memory allocated when
allocated at allocated at the method is executing
the time of time of method
class loading gets call and get
and deallocated
deallocated at when method
time of class execution gets
unloading completed
8 static int a = int a = 12; {
55; int a; int a = 55;
static int a; }
9 - - If name of static variable
is same as local variable
then will use
[Link]
We have seen all methods and all variable declaration and calling
inside same class
Calling Methods and Variables from different Classes
Static method : [Link]
Non Static method : [Link]
Class 1 :
Class 2
Output:
Write a program to display marks of 3 student appearing for
the following subjects
Subjects
Maths
Physics
Chemistry
Student Name
Avdhut, Raju, Seema
Hint :- (subject should variable, student should be objects)
- Memory optimization
- Java code minification
- Easiness of code (Easy Maintenance)
Example
Arguments and returns types:-
1. Without Argument and Without return type method
Example:
Void is return type which return nothing (Null)
2. With Argument and with return type method
Example:
3. With Argument and no return type method
4. Without argument and with return type
Example:
Example of all method modification with arguments and returns
Write a program to display marks of 3 student appearing for
the following subjects
Subjects
Maths
Physics
Chemistry
Student Name
Avdhut, Raju, Seema
Hint :- (subject should variable, student should be objects)
- Memory optimization
- Java code minification
- Easiness of code (Easy Maintenance)
Constructor:
Def:
Constructor is specialize method which get executed at the time of
Object Creation
Rules of Implementing constructor:-
- Name of constructor should be same as class name
- Constructor doesn’t have return type
- Constructor can accept arguments
- Multiple constructor can be present in same class with different
argument
- Constructor can call another constructor inside same class
using “this” keyword
What is constructor chaining of same class?
- We can call another constructor inside constructor using this
keyword for matching argument of another constructor
- However we can only use this keyword on very 1st line of that
constructor and we can use it to match argument of only one
another constructor
- With such arrangement upon creating one object we can
execute chain of constructor
- This concept is known as Constructor chaining in same class
Rules of Constructor chaining:
- “this” keyword should be use on very 1st line of constructor
- “this” is use for argument matching of the constructor that you
want to call inside current constructor
- Only one another constructor can be called inside constructor,
i.e. only one this keyword can be present to call another
constructor
Example: (Constructor Chaining and rules)
Task 1 (Need to get output of above program in format like it
should print Constructor 1, Constructor 2, Constructor 3)
Task 2 (using constructor)
Write a program to display marks of 3 student appearing for
the following subjects
Subjects
Maths
Physics
Chemistry
Student Name
Avdhut, Raju, Seema
- Memory optimization
- Java code minification
- Easiness of code (Easy Maintenance)
Example of constructor using test program
Operator:-
[Link] Expression Initial Initial Final Final
value of x value of y value of value
x of y
1 Y=++x 10 11 11 11
2 Y=x++ 10 10 11 10
3 y= --x 10 9 9 9
4 y=x-- 10 10 9 10
Example:-
How to debug:
- Add breakpoints by double clicking on line
- Right click run as debug
- Press f6 for step over
If-else
- This is control statement which execute “if” body once the
condition is true otherwise it execute “else” body
Output:
else chalega
- Curly braces are optional in if-else, provided we have only one
line statement in it
- Without curly braces, the statement should not be declaration
i.e. initialization of local variable
Exam:
If u want to write condition to match the variable use “==”
For greater than sign “>”
For less than sign “<”
If u want to write condition to unmatch the variable use “!=”
Example: (for not equal to )
Else if :-
Or operator:-
Either one condition out of all condition should be true then only
body will get execute
if((a!=b)||(a==b)) {
}
and operator:-
All conditions should be true then only body will get execute
Output:
Task 2 (using if-else)
Write a program to display marks of 3 student appearing for
the following subjects
Output:
Summarization:-
Loops:-
1. While loop
2. Do-while loop
3. For loop
What is loop?
- It is used to initialize variable as well as use to repeat certain
logic number of time
1. While Loop:-
Output:
Infinite While Loop
Output:
Do-while loop:-
Output:
Task to Print even numbers from 1 to 100 using while loop
Output:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44
46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86
88 90 92 94 96 98 100
Task to Print odd numbers from 1 to 100 using while loop
Output:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41
43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79
81 83 85 87 89 91 93 95 97 99
For Loop:
Output:
0 1 2 3 4
Infinite Loop using For
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
44 c45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
63 64 65….. infinite loop
Even Number using for
Odd Number using for
Output:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41
43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81
83 85 87 89 91 93 95 97 99
Write Program to design following Patterns
*****
*****
*****
*****
*****
Output:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
Break and Continue:-
Break –
Break is used to break or stopped particular loop and make the
control out of loop
Example:
Output:
Continue:-
Continue keyword is used to jump to the next iteration whenever
continue keyword get execute
(Skipped ho jayega condition wala iterator)
Example:
Output:
1
2
3
5
Out of the loop
Print odd number using continue keyword
Output:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43
45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85
87 89 91 93 95 97 99
What are the keywords in JAVA ? tell any 5
keywords in JAVA?
- Keywords are nothing but the predefined words in java which
has specific meaning in relation with syntax and operation
- There are 52 keywords present in java
Example:
public
class
static
this
int
new
OOPs Concepts in JAVA:-
“Object Oriented Programming”
- Inheritance
- Polymorphism
- Encapsulation
Inheritance:
- Inheritance represents relationship through which every
property of parent class will be by default available to the child
class
- This relationship can be established by using ‘extends’ keyword
- Where public class ChildClass extends ParentClass
Here child class is extending parent class that means child will be
having all the properties available to him from parent class
Example:
Parent Class:
Child Class
Output:
Types of Inhertiance:
1. Simple Inheritance
2. Hierarchical Inheritance
Example:
Parent Class
ChildClass
ChildClass1
Output:
3. Multilevel Inheritance
Example:
Parent Class
ChildClass
ChildClass1
Output:
Limitations of Inheritance:-
- Only child class can have access of parent class , Parent class
cannot access child class property
- Multiple Inheritance is not possible
- Cyclic Inheritance is not possible
Diamond Ambiguity Inheritance
Advantage of Inheritance:
Inheritance: Reusability
Ex.
Inheritance with respect to Variable:
- All the global variable will be available to the child class by
default like methods
- If the same name of non-static variable is available in parent
class then in the non-static method of child class it can be
access through “super” keyword
- If we are accessing same name variable which is present in
parent as well as child by calling only child object and name of
that variable it will point to nearest non static variable
- In static method to access same name variable of parent class
need parent object
- If the same name of static variable is available in the parent
class and child class then we can access particular variable
through [Link]
- If we called by direct name in this situation it will call nearest
static variable
Imp Question:-
Does global variable follows inheritance?
If name of non-static var in child class is same as name of non -
static variable in parent class, then how will u call parent class
non static variable inside child non static method?
What if name of static variable in parent class is same as name
of static variable in child class, how will u call parent class static
variable?
Constructor with respective Inheritance:-
Does constructor follows inheritance?????
Constructor Types:
- With Argument Constructor (Parameterized Constructor)
- Parameterized constructor is a type of constructor where it has
some arguments as an parameters and upon creation of an
object we need to provide values in object argument to call
specific constructor having respective arguments types
- No Argument Constructor (Without Argument Constructor /
Parameter-less constructor )
- No Argument constructor is without argument constructor
where upon object creation constructor will get execute
- Default Constructor
A default constructor is constructor that either has no
parameters, or if it has parameters , all the parameters has
default values
If no user defined constructor exist for parent class and one is
needed in child class, then the compiler implicitly declares a
default parameter-less constructor
Does constructor follows inheritance?????
Constructor inheritance is not possible:-
- Child class constructor will automatically call parent class
constructor in all cases whether constructor is present in
parent class or not, if not present it will call default constructor
of parent
- If child class constructor type doesn’t matches with the parent
class parameterized constructor we cannot call parent class
constructor directly this shows Constructor Does Not follows
Inheritance
- So to match the type of constructor will use “Super” keyword,
and if we required to use special keyword like super to match
the types it shows parent class property is not by default
available to child class
This proves Constructor does not follow Inheritance
Constructor Chaining:
Constructor chaining is process of calling one constructor from
another constructor with respect to current object
- Within the same class it can be done using “this(argValue)”
- Different class it can be done using “super(argValue)”
Example:
Parent class
Child class
Output:
Just Additional Thing to Know!!!!!!
What if child class constructor is not present, so upon object
creation it will still call parent class default constructor (No
Argument Constructor) and through that it will execute parent user
defined constructor
Example:
Parent Class
Child Class
Output:
But here parameterized parent constructor can-not be called directly
as inheritance not followed
Example
Parent
Child
Access Modifiers/ Access Specifiers:
The keywords which tells the accessibility of particular method,
Variable or class is called as Access Modifier
1. Access modifiers applicable to class
- Public
(Provides accessibility throughout the project)
- Final
(Whichever class declared as final it cannot follow inheritance i.e. the
class which has declared as final cannot be extended by another
class)
However we can still calls the method of that final class in same
package by creating an object for Non static method and using
[Link] for static method
- Using final keyword we cannot access the class outside the
package
- <default>
(The class which declares as <default> can be accessible within the
package and cannot be accessed outside the package)
- Abstract (It is Access modifier which is applicable to class as
well as data members for more info check Abstraction topic
below)
2. Access modifiers applicable to Data Members (Methods,
Variables)
Public-
(If we declare method or variable as public then it will be
accessible throughout the project)
<Default>-
(If particular method or variable declares as <default> then it
would be accessible throughout package only and cannot be
accessed outside package)
Private –
(If particular method or variable is declared as private then we can
access method or variable only in the class where it was defined)
Protected-
This is mysterious keyword
<default> + inheritance
- It will be accessible within package
- And it will be accessible outside package only when there is
inheritance involved between classes
Final –
- If we declare a variable as final then we cannot perform
reassignment of that variable value except the place where it
got initialized
- If we declare final on methods then even if class is inherited still
child object cannot access outside package final method and it
cannot be overridden in same or outside of package
Polymorphism:-
Def:-
Methods having different forms with same name is called
polymorphism
Types:
- Overloading
- Overriding
Overloading:-
- A method can be called as overloaded method when name of
method is same but the arguments are different in same class
as well as in inherited class
- Same name method having different signature is called as
overloading
Example: Overloading in same class
Output:
Overloading in Inherited class
Parent
Child
Output:
Is overloading possible in different class which is being inherited
from parent class? -- Yes
Can we overload Main method?
Yes main method can be overloaded
In given class we can have same name method like “main” but
arguments should be different, same for the inherited class where
main method overloading is possible
Jiska ref hey uska method compiler suggest karega and wahi
chalega in Oveloading
Case 1 : (Child objRef = new Child();
Using child object and child reference
Parent Class
Child class
Output:
Case 2 (Parent objRef = new Parent)
Using Parent object and Parent reference
Parent
Child
Output:
Case 3 (Parent objRef = new Child)
Using Child object and Parent reference
Parent
Child
Output:
Case 3 (Child objRef = new Parent)
Using Parent object and Child reference
Parent
Child
This case is not allowed as parent object cannot be referred by child
reference due to inheritance property where only child has access
over parent property and parent object cannot have access to child
property so it cannot be referred by child as well
Overriding:-
A method can be called as overridden method if the name of
methods and signature in the child and parent class is same
- Inheritance must be present to override the method
- Overriding in same class is not possible
- Main method cannot be overridden
Parent
Child
- Main method is static method which does not required any
object creation
- To call main method from another class into different class we
will use [Link]
- This shows inheritance is not been followed when we are
having main method overridden between in two classes
- So we can conclude main method cannot be overrided as
overriding of main method is not following inheritance
Jiska Object hey uska method chalega but compiler ref class suggest
karega in Overriding
Case1 :-
Parent
Child
Output:
Case 2-
Parent
Child
Output:
Case 3
Parent
Child
Ouput:
Case 4
- Child refObj= new Parent();
This is not possible due to inheritance property
Can we override Static methods?
- Overriding concept is based upon run time object
- So when we use object of particular class that if that class has
overriding method then same class method will get executed
regardless of reference class
- So as per above scenario we can conclude overriding is base
upon object and not on reference
- However in static methods objects are not required, static
methods get static memory at the time of class loading during
compilation of program
- So overriding is Run time polymorphism and not compile time
polymorphism
- That’s why static method cannot be overridden however static
method can be overloaded
Important Notes Overloading:-
- Overloading is also known as Compile Time Polymorphism and
Early binding
- Reason- On compilation time of program for Overloading
method we get to know which method will get execute
- In overloading resolution is based in Ref variable of object
Important Notes Overriding:-
- Overriding is also known as Run Time Polymorphism and Late
Binding
- Reason- On Run time of program for Overriding method we
get to know which method will get execute
- In overriding resolution is bases on Run Time Object
Method Hiding:-
- If two static method tries to get override then it is not
overriding but it is referred as Method Hiding
- It means method resolution is bases on Reference type variable
of an object in terms of static method but not on run time
object
- Also, calling static method after creation of an object and it’s
reference is unethical or restricted in java , which is not good
practice and implementation of java program
Polymorphism With Respect to Variable:-
int a = 20;
- Variable resolution always taken care by compile based
reference type whether the type of variable is static or non-
static
- In short overriding concept is not applicable to variables, only
applicable for methods
Constructor does not follow concept of Overriding
- Inheritance must be present in overriding method
- However constructor does not follows inheritance
- To implement constructor name of constructor should be same
as class name, but overriding concept is possible only for
different classes where inheritance is involved, so different
classes would have different names
- So we cannot override the constructor which will have same
name and same arguments
Advantages of Polymorphism:-
- Flexibility
Abstraction:
It is process of hiding the implementation details and showing only
functionality to the user
Example:
Abstraction shows essential things to the user related to
functionality and hides the internal details, like while sending a
SMS, user will only allowed to type message and click on send
button, user is not allowed and aware about internal processing
of how does SMS sending works (e.g. encoding decoding)
Abstraction let user focus only on usability of an application
and not on the implementation
Ways to achieve Abstraction in JAVA:-
- Abstract (0 To 100% abstract method)
- Interface (100 Abstract method)
Abstract:-
- It is an Access modifier which is applicable for class as well as
methods
- If we do not have an idea of complete implementation of any
method currently
- Means we know major part of the functionality of project, but
we are not sure about the implementation right now
- Then we should declare or use abstract modifier
Point to Remember:-
- If we declare a class as abstract then it is not necessary to
declare an abstract method
- But if we declare any one of method as abstract then that class
must be declare as abstract class
- Every child class of abstract class has to implement all the
unimplemented methods(Abstract methods)
- If all abstract methods implementation is not possible then in
this situation we will write child class also an abstract class and
we will declare the unknown method as unimplemented
abstract method and we will implement know method as
implemented non abstract method
Example:
Parent
Child
- We cannot create object of abstract class
- But we can access the complete methods from abstract class by
creating an object of fully implemented child class (Concept of
overriding)
Example:
Static Method Abstract Discussion
- We can implement static method in abstract class having
complete body of that static method i.e. static method should
be fully implemented in abstract class
- We cannot make static method as abstract reason abstract is
based on overriding concept and static method cannot be
overridden
- Abstract class extension will work inside package only
- You cannot use final and abstract modifiers together reason
final does not allow inheritance and for abstract overriding is
necessary which requires an Inheritance
Ex
Points to remember in terms of Access Modifiers:-
- Using only ‘abstract’ keyword we will not be able to access
the class outside the package
- Similarly using only ‘final’ keyword we will not be able to
access the class outside the package
Important Question!!!
How to access ‘abstract class’ or ‘final class’ outside the package?
It is possible to access abstract class or final class outside package
with the help of combination of access modifiers
Allowed Combination of Access modifiers In JAVA
- Using allowed combination we can access the final and abstract
class outside package
Public can be combined with final – outside package accessibility
Public can be combined with abstract – outside package accessibility
Default can be combined with final – within package accessibility
Default can be combined with abstract – within package
accessibility
Note:-
Final cannot be combined with abstract
Public cannot be combined with default
Interface:-
(Extends and Implements)