Session 16- Java OOPS Concepts - Data Abstraction | Interface Concept in Java

SDET- QA14,151 words

Full Transcript

right so in the today's session uh we going to see 

interface and so before that so we have seen some of the objectoriented programming Concepts 

the last classes and the class object then encapsulation polymorphism and then we have seen 

inheritance right these are the concepts we have covered so far and today uh we are going 

to see one more concept of objectoriented programming which is data abstraction so this is 

another concept of object oriented programming concept so the data abstraction we can achieve 

in two different ways by using abstract class and also by using interface concept so for every 

objectoriented programming concept there will be a technical concept associated with that for 

example uh if you want to achieve polymorphism right overloading is a concept through overloading 

we can achieve polymorphism so by using Setters and gets we can achieve encapsulation so like 

this data abstraction also we can achieve by using abstract class and also interface so first 

of all let us understand what is data abstraction abstraction means what hidden so the functionality 

is hidden so that's called abstraction so what is data abstraction means so is a process of 

hiding implementation as per java definition it's a process of hiding implementation and only 

showing the functionality to the user abstraction is a process of hiding implementation details and 

showing only functionality to the user what does it mean let me take some examples suppose uh we 

are using some device suppose we are using mobile phone we know how to use mobile phone right 

but how they have implemented all the apps and how they have developed internal Hardware 

all those things we are not we don't know right we are using the device but we don't know exactly 

what they have implemented internally so the that is part of the heaten right so like this in 

the real uh life we can see so many things we are still using it but we don't know exactly how 

they have implemented right so like this that's called abstraction so abstraction is nothing 

but a process of hiding the implementation but only showing the functionality to the user 

we can use it but we don't know exactly how they have implemented so that is a meaning of 

data abstraction abstraction is a process of hiding implementation details and showing only 

functionality to the user so this is also a kind of a security kind of a security and privacy 

kind of a feature like encapsulation we ear we discussed right so we can access the data only 

through sets and gets we cannot directly access the data okay and similar here also uh we can 

indirectly access all the methods and variables we cannot directly access that's abstraction so this 

we can achieve using two different approaches in Java one is by using or by creating abstract class 

and the second approach is by using interface concept so these are two different uh Concepts 

which we have through which we can achieve data abstraction concept and again if you take these 

two concepts abstract class by using abstract class we cannot achieve 100% abstraction but by 

using interface we can achieve 100% abstraction so interface is more advanced concept than 

abstract class abstract class interface the objective is same the purpose is same okay but 

when you compare again these two interface is more effective than abstract class okay so 

interface is having more number of features and we can achieve more high level abstraction by 

using interface 100% abstraction we can achieve but when I use abstract class there are some 

Loop holes are there so that is the reason we cannot achieve 100% abstraction so if you compare 

these two interfaces more preferable when you want to achieve data abstraction concept okay so 

we will directly start with interface and we will understand interface and all that stuff and 

once you understand the interface concept later I will compare interface with abstract class okay 

then you will understand what is the difference between these two and what are the limitations of 

abstract class what we can additionally achieve by using interface concept okay because these are 

all security privacy related features we don't need to focus more on this but interface is most 

important because most of the times in automation also sometimes we use interface concept we will 

try to use some existing predefined interfaces which are already there in selenia web driver 

so for that we have to understand interface so we directly jump into the interface and once you 

understand interface then finally we will compare and how to create an abstract class and what is 

the difference between interface and abstract class class interview prospective this is most 

important but practically we never use abstract class okay if you want to achieve data abstraction 

directly we will use interface concept but inter prospective you need to understand the differences 

between abstract class and interface okay so directly we'll start with interface concept and 

which is very very important topic and you have to focus each and every Point what I'm saying 

and I will also show you the Practical examples for every point okay so let me put some points 

here uh what is an interface and all other the points so first thing the first point we 

already know about uh class right what is class what is object and what is class contains 

class contains the variables and methods and we can create an object for the class so we already 

know these points now when you come to interface interface also seems very similar to the class 

but interface is having some more attribute some more type of behavior and there we can def class 

with interface okay so first we will see what is an interface an interface is a blueprint of class 

an interface is a blueprint of class what does it mean when when you create an interface the 

syntax is almost similar to the class just that the keyword is got changed suppose if you 

want to create a class we will say class keyword class class name and then the class contains the 

variables and class contains the methods this is syntax of the class when you create an interface 

also we use the same syntax but only the differen is we use interface keyword instead of class we 

use interface keyword and interface name and the interface also contains a variables and interface 

also contains the methods so syntactically seems very similar only the class keyword is different 

and class contains the variables and methods even interface also contains a variables and methods 

so that is the reason we can say an interface is a blueprint of class so when you're creating an 

interface almost syntax is similar so which is the reason we can say an interface is a blueprint 

of class and again I will tell you when we have to use interface okay what are the advantages 

you will get interface with real time scenario I will show you first we will understand what is 

interface and how to create and how to work with it now the second point an interface contains 

a final and static variables interface contains only final and static variables means what when 

you create in the class we can create any type of variables we can create static variables we can 

create non-static variables we can create final variables we can create non final variables every 

type of variable we can create in a class but in interface we can create only final and static 

variables and even if you not specify these keywords still if you just create a variable 

in interface that will be treated as final and static variable both keywords are appli app 

for that particular variable so in interface the variables are by default final and static okay you 

don't need to specify the keywords final keyword static keyword but as soon as you created a 

variable that is a final and static variable by default okay so interface contains a final 

and static variable so what is meaning of Final in the last classes we have already discussed 

about these t keywords what is the use of final keyword for the variable when you create a final 

variable the value of the variable is constant okay we cannot change similarly what is the use 

of static variable when you create a variable is a static that is a common variable across all 

the objects shared variable okay so by default whenever you create a variable in interface 

that is final and also static and we don't need to specify the keyword also by default the 

variables are final and stting that's the second point now the third point is interface contains 

a abstract methods also allowed default methods and static method from java 8 from java 8 before 

Java 8 versions interface allowed only abstract methods we can create only abstract methods but 

after Java 8 we can also create default methods and starting methods in interface so this point 

is most important we need to understand what is an abstract method interface contains the abstract 

methods initially initial days but after Java 8 onwards they also allow to create default methods 

and also static methods in interface and what is an abstract method abstract method is a just like 

a normal Java method which is having only the Declaration part there is no implementation for 

this method which is called abstract method okay for example in the class if I create a method 

how we will create we will specify the return return type then method name and if you have 

parameters you can specify parameters and here you will Implement implementation we will have 

in case of interface is we will have abstract methods abstract method means what only you have a 

signature means return type method name and if you have a parameters you can specify the parameters 

in the bracket and then semicolon so this is only signature there is no implementation so this type 

of methods are called abstract method so abstract method means which is having only signature so an 

abstract method is a method contains a signature but not body which is also called unimplemented 

method which is also called unimplemented because we haven't implemented that method we have 

just declared that method in the interface but we haven't implemented that method so such 

type of methods are called abstract methods so when I create an interface interface allowed 

to create abstract methods so before Java eight versions interface allowed only abstract methods 

we cannot implement this method okay by default this method is an abstract method we cannot write 

implementation just like a class if you're trying to implement this method like this it will give 

you an error because implementation not allowed in interface here we cannot Implement so the body we 

cannot Implement in the interface the method body we cannot Implement in the interface it is not 

allowed so only abstract methods are allowed in Java but from java 8 onwards it is also allowed 

default and static methods means what these methods we can have implementation default methods 

and static methods we can have implementation implementation also we can write but only abstract 

methods doesn't have any implementation okay this is point very very crucial so interface 

contains abstract methods means there is no implementation only the Declaration will be 

there only signature we can write and the method should end with the semicolon so this type of 

method is called abstract method just a moment guys okay so the interface contains only abstract 

methods from java 8 onwards interface is also contains a default methods and static methods 

so default methods and static methods can have a implementation but abstract methods doesn't 

have any implementation I will tell you what is default method static method everything so 

by default whenever you create a method the access modifier will be allocated for that that is 

called default default is an access modifier these are all not buil-in classes methods or anything 

else don't assume like this I will explain each and everything clearly okay just try to understand 

this point while creating an interface I will tell you what is abstract method what is default what 

is static all those things now the fourth point so first we'll understand all the points then each 

point I will Implement practically and then I will show you okay now the fourth point we already 

understood abstract method is a method contains signature but not body means we already understood 

there is no body for the abstract method like this only written type name of the method if you have 

any parameters you can have these parameter that's semicolon there is no implementation that's type 

of method called uh abstract method fifth point so methods in interface are public so by default 

whenever you create a method or whenever you create a method in interface by default they 

are Public public means is a access modifier and normally if you want to make a method as a 

public we have to write a keyword like this if it is a class if you want to make the method as a 

public we have to specify the public keyword then only this method become public method everywhere 

we can access but in interface even though you don't specify this public keyword by default the 

method is public the methods are public okay so all methods in interface are by default public 

even though you don't specify access modifier but in a class if you create any method like this 

you don't specify any access modifier then what is the default access modifier will assign to 

this method in case of class in case of interf pH by default the methods are public even though 

you have not assigned any specific modifier that is a public but in class if you don't specify 

any access modifier in front of the method what type of access modifier it will allocate it is 

default access modifier will allocate in case of class default access modifier will be allocated 

okay remember this so you no need to write the default keyword actually in in the class so if 

even if you don't write it by default this is a default method this is a default method in 

the class okay but in interface uh the methods are public by default the methods are public if 

you want to make a method as a default you have to specify the default keyword if it is an 

interface that is a major difference okay so anyway we will compare this with class later 

first of all focus on interface so interface contains a by default all methods are public in 

interface now the sixth Point interface supports the functionality of multiple inheritance so 

what is multiple inheritance we have multiple parents having one child so those parents we 

can create an interfac so multiple interfaces we can Implement by using single class that single 

class is a child class but if you have a multiple parents classes so we cannot extend we cannot 

Implement so by using interface we can achieve multiple inheritance next we can Define interface 

with the interface keyword we already seen now the eighth point a class extends another class 

suppose if you have a two classes which keyword we will use one one class to another class if you 

want extend extends keyword we will use similarly an interface extends another interface so if 

you have one interface parent interface I want to get everything into child interface still 

we use extend keyword but a class implements another interface class to interface we can do 

implementation okay so I will clarify this point so just observe this I have one class let's say 

this is my class C1 and another class class to class use extends because this is the extension 

of the previous class then C2 will get everything from the C1 and both are having implementations 

now I have an interface and another interface and this is a parent interface this is a child 

interface now I have want to get everything from the parent interface to child interface here 

also we use extends interface to EXT interface also extends this is extension of the pr previous 

parent interface now I have an interface and what is an interface contains abstract methods along 

with the default and static methods so default and static methods anyway we will have implementation 

but only the abstract methods doesn't have an implementation so if you create an interface we 

need at least one class this class will Implement all the method from the interface anyway default 

methods and static methods will be implemented the implementation is there only our concern is about 

abstract methods so interface contains abstract methods abstract method is nothing but what there 

is no implementation but who will Implement those abstract methods interface cannot Implement only 

interface contains abstract method declaration so if you want to implement those abstract methods 

we need at least one class suppose if I create one method here which is abstract method and this 

particular method we have to implement in child class so here we have to use implements keyword 

so class to class extends interface to interface also extends but interface to class we have to do 

implements but class to interface tell me class to interface extends or implements suppose I have 

a one class and child has interface extends or implements this is not possible class interface 

is not possible why it is not possible see very carefully interface contains a abstract methods 

default methods static methods so we don't worry about abstract uh we know need to worry 

about static methods and default methods because they are already having implementation 

so CH class also will get that implementation no problem we have concern about only abstract 

methods so in interface abstract methods will be there means there there is no implementation 

for abstract methods so those methods we can Implement using a class so that's the reason we 

have to use implements class but if you look at this particular scenario what is class contains 

class contains what all types of methods right starting methods default methods implemented 

methods all methods are implemented here but when you get all of them in interface but here 

interface not allowed implemented methods right so class contains implement mented methods but how 

come interface will get the implemented methods interface not allowed right so implements 

interface not allowed to create implemented methods only abstract methods are allowed but 

when you get class into interface here interface should allow implementation also but by default 

interface doesn't allow the implementation only abstract methods are there but in the class we 

have implemented methods so how can how can we get implement methods into an interface we 

cannot so that's the reason this combination is not possible so class to class we use extends 

interface to interface also we use extend suppose if you have some abstract method here same 

abstract method will come into I2 also but again if you want to implement this abstract 

method again we have to create one more class here here we have to do implements got my point so 

interface alone is not useful interface along with the class is useful whenever you see an interface 

which contains an abstract methods what is the use of abstract method what is the purpose of creating 

a method first of all we need to write some logic inside that right when I create a method there 

is some purpose that method should perform some task but if you simply create an abstract method 

what is the use of that method right so somebody should Implement that ract method then only it 

will be useful but interface cannot Implement so we need to take the help of a class which will 

Implement those abstract methods which are coming from parent interfaces so interface alone is not 

useful interface along with the class is useful so class we need to implement all the methods 

abstract method from the interface okay so just like a class we can also extend from interface 

to interface suppose this interface is already designed by somebody else and we want those 

variables we want those methods so again we don't need to recreate them in our own class we can 

just extend that interface into our own interface then automatically we will get all the variables 

and all the method from the parent interface to child interface just like a class how we have 

used inter inheritance concept this is also inheritance inheritance is applicable for class 

as well as interface okay so what is the use of extend in the class in the last classes we already 

discussed what is the use of inheritance same thing here also if something is created already 

in interface and instead of recreating again and again multiple times and avoid duplication we can 

simply extend that interface to another interface so that we will get everything from parent 

to child interface again these methods we can Implement by using any other class okay class to 

class we use extends interface to interface also we use extend interface to class we use implements 

because this interface should be implemented by using a class and class interface is not possible 

and why it is not possible because class contains implemented methods once you implement or once 

you extend interface not allowed implementation so you cannot get it so this is a point eighth 

point class can extend another class an interface extends another interface but class implements an 

interface okay is this point clear everyone eth point which is related to inheritance now the last 

point we can create object reference for interface but we cannot instant the instantiate interface 

which is another important point that means we cannot create an object for interface if we have 

a class we can create an object for the class but for interface we cannot create an object we cannot 

create an object that means we canot instance here there are two terms actually object reference 

instantiate we need to understand the difference between these two object reference instantiate 

what is this suppose if you have one class created let's say we have created one class a okay let's 

say I have created one class called test now for this particular class how to create an object 

how to create an object by using new keyword so new test if you leave statement like this I'm not 

using any reference variable here just I'm saying new test this will create an object so new keyword 

will create a object of test type but if you want to work with this object we need some variable 

reference variable is required even though if you don't have a reference variable still we can work 

with the object I will tell you earlier we haven't discussed this suppose if you want to create a 

class suppose you have a class called test and how to create an object for this we can say new 

test this itself is an object okay suppose I say new test this is another object again new test 

this is another object so three objects will be created like this three objects will be created 

so if you want to work with this object you can say new test so we can directly refer this Suppose 

there is some variables or there is some methods here how can we access with this you can directly 

access like this new test dot method name you can directly do that so this is the object from the 

object I'm accessing M okay so instead of using this every time what we can do we can put some 

reference variable okay some X test type so by using X we can do X do M this is the way we are 

using currently so actually who is object who is object reference here this part is called object 

or instantiation we can call it as instantiation okay instantiate or instance or the object but 

what is this X X is not an object X is a reference variable this variable is pointing to the object 

you understood the point everyone so actually who is an object here this part this is called object 

this is called object this is called object this will new keyword will create an object to refer 

this object we are using some variables so object reference means what this one this is called 

object reference variable instantiate means what new test this is called instantiate okay you got 

the difference everyone what is object reference variable what is instantiation instantiation means 

what the process of creating an object that is called instantiation so here where we are creating 

an object here new test this is called object creation so this part is called instantiation 

so now based on that we will understand if it is a class we can create we can instantiate we 

can also create an object reference variable both are possible but if it is an interface we 

can create only object reference variable but we cannot create instantiation that means we 

cannot create an object but without creating an object how can we create reference variable why 

do we need reference variable you got my point if you create an object if I say new test object is 

created then we need some variable test type of variable we require so this particular variable is 

referring to this object when you create an object then reference object reference variable is needed 

but in case of interface if you're not able to create this object why we need this interface type 

of variable object reference we can create but we cannot instantiate means object we can we cannot 

create but object reference variable we can create how come it is possible that is a point okay so 

how it is possible means for example if you have an interface interface should be implemented by 

using some class must be this must be some class without class there is no with use of interface 

right so as soon as you create a child class what you will do in this child class whatever methods 

are there in the parent interface you will get everything into child class abstract classes 

abstract methods also you will get into the class so these abstract methods we will Implement using 

this class now we can create an object for this class okay I say new C this will create an object 

and normally what you will do whichever class you created an object we will create a variable 

also with the same class like this so we created a object for the C class so the variable type is 

also C this is a normal way we do it but suppose if this class is a child class of interface then 

what we can do is the object we have to create for the class but the reference variable we can create 

for the interface this is a point that means the variable of interface can hold the object of child 

class okay when you can create an object for this child class that object we can hold into another 

variable that variable can have interface type so forget about this one just think about this 

one this is clear everyone right so whenever you create an object for the class we can hold that 

object into a variable that is also type of the same class whichever class we created an object 

the variable type is also same this is clear everyone right now come to the interface concept 

when you come to the interface concept we cannot say I obj equal to new I we cannot use new keyword 

for interface because we cannot instantiate interface we cannot create an object of interface 

so then what we will do now if you want to access everything from this interface what you will do 

now we will create an object of the class which is implemented this interface you have to listen 

very carefully we cannot to directly create an object for the interface then if you want to 

access everything from the interface what you will do you can access them through the object 

of class so some class will be there which is implemented this interface right so we can create 

object of this class and through the object we can access everything or not because this class 

is implemented everything from interface parent interface so we can create an object of the CCL 

class and we can access everything by using this object this we already know but now what is a 

new thing here is new see we created object of C right for this object we can also hold into the 

variable that variable type can be interface so whichever interface is implemented this class 

we can create a variable for interface but we cannot instantiate interface that is a point 

that means whenever you create an object of the CH class that object we can store into same 

type of variable or we can store into interface type of variable that means an interface variable 

can hold the object of child class this the object is referring what child class right so the r 

variable of interface can hold hold the object of class this is the point here clear everyone 

we can create object reference but we cannot instantiate interface this point is clear everyone 

so why we need this why we not all these things I will explain need to have some patience okay you 

understand the point difference between the class and interface is with respect to this point if it 

is a class we can instantiate we can also create object reference both you can do but in case of 

interface we can do only object reference but not instantiate but again another question will comes 

if you don't have instantiation if you don't have an object why reference variable is required that 

is the reason I'm giving this examp so interface is a parent which is implemented by using a class 

so by default when you create an object of this class you can access everything from this one 

and this one and object reference variable is same and instantiation is also referring to the 

same class but what I'm saying if you create an object for the C class this object we can also 

hold into variable that variable type can be C or this variable type can be I that's what I'm 

saying so if the variable type is C that's fine because the object is created for what CL class 

this particular class this is correct and instead of C we can also specify this interface name also 

instead of class I can say I also here that means this object is implemented for what this interface 

only right there a reason this object we can hold it into interface variable so interface variable 

we can create object reference we can create for interface but we cannot instantiate interface 

that means here we cannot write new I we cannot write new I that is called instantiation so 

instantiation is not possible but the reference variable we can create for the interface and 

without having having any object how can we create a variable is this is an example the 

object we will create for the child class the variable can be interface variable so interface 

variable can hold the object of child class that is a point okay so now we'll see practically all 

the points one by one and uh then you will able to understand very clearly and one important 

question here if interface contains abstract methods what is the use of abstract method because 

the purpose of creating method is what it should perform some task if you just create an abstract 

method interface which is having only signature there is no implementation what is a use of 

that method that's the first question the second question is what why we need to create an 

abstract method when is a requirement whenever you start creating method you will implement it but 

without having any implementation just creating the abstract method what is the use when you will 

create who will Implement that abstract method interface cannot allow implementation of abstract 

method then who will Implement that class who will Implement that method and uh again suppose 

let's say I have an interface like this these are all different questions and this interface is 

implemented by us class first of all why we have to create an abstract method here again we have to 

implement this abstract method in the class same abstract method we will Implement here why we 

can directly create an abstract we can directly create that method in the class itself right with 

the implementation why we specify abstract method and why again implementing by using another class 

this process is lengthy right so why we need to do all these things so let me explain this with 

the real scenario and we need to think this in the development point of view okay then only we 

will understand this so why we need interface and why we have to create abstract methods in 

interface and later why again we need a class separate class to implement interface instead 

of that we can directly create a class we can directly Implement that methods why the use of 

interface in that case okay so interface is not only for multiple inheritance guys interface is 

also having some other advantages so let me just clarify that what is a real usage of interface in 

the real projects and why we will prefer to create interfaces okay so developer so what is the 

responsibility of the developer what developer will do normally he will develop the software 

but to develop the software he has to he will create he will first what he need actually what's 

the input he need so if anybody want to develop a software or develop some application okay some 

application he want to develop as a developer so what he need only requirement is enough first 

thing is has to know the requirement second thing is what requirement means what what what to 

develop what requirements is what to develop if you know what to develop then immediately you 

can start developing right you don't know only you know what to develop that says requirement but 

how to develop right you know you should know that also right how to develop that is called 

design okay you have to whenever you want to develop any software or any application you have 

to know what to develop and how to develop and how we will know what to develop if you read the 

requirement documents so you will know exactly based on the customer or client requirements 

you will know what to develop and what they are expecting from the application but how to 

develop then based on the requirement we have some kind of design and based on the design what 

the design contains high level modules lowlevel modules and again each and every module how many 

classes we have to create every class what are the variables method we should have so this is all 

about design part so if you want to develop any application we have to know at least two things we 

have to know requirement that says what to develop and we have to know the design how to develop if 

you know these things you can start development right this is the scenario now in the real time 

what happens is initial days you will have only requirement and design will take some time because 

design will not be available immediately so once you get a requirement based on the requirement 

you will have a design documents so this will take a lot of time creation of design documents 

will take a lot of time but initial days you will get only requirement so with that requirement 

as a developer what you will do is you will create interfaces okay interfaces you will create 

whatever interfaces you need you will create like this and whatever you want to develop you will 

understand the scenarios right and based on the scenarios you will create abstract methods only 

signature there is no implementation until unless you know the design part you canot to implement 

those methods until unless you know the how you cannot Implement them so initially you have only 

requirement for example take a banking application in the banking application only fund transfer 

is one of the requirement so here you will just create one abstract method for fund transfer 

that's it you will not implement this similarly login you will just create one method and balance 

verification you will just create an abstract method because of you know the requirement but 

you don't know how to implement them so initial days developers will create interfaces like this 

because they know only the requirement part they don't know the design part so after few few 

days of after few months later on once they know about design part then what you will do these 

interfaces will Implement by using again different classes so not only one class different classes 

can Implement suppose if you create one interface that can be implemented by using multiple classes 

with multiple implementations suppose if you have created fund transfer method right this method we 

can Implement in the different ways in different approaches so later once you understand the 

design once you get a design then you will start implementing these abstract methods by using 

separate classes without disturbing this interface so this is the real scenario so that there exactly 

we use interface concept so initial days we will just have only unimplemented methods because we 

know only requirement part we just specify all the requirements in the form of abstract methods 

later once you know the design you will implement this inter interfaces by using any other classes 

okay so this is the purpose actually so why we need interface and when we have to create an 

interface and uh again later we need to create a classes to implement those interfaces okay 

so now let us see the Practical implementation of interfaces all these points we will discuss one 

by one with the Practical example so now go to the Eclipse let's go and create new package for today so day 16 okay now in this I'm going to create uh 

okay so just like a class we can also create an interfaces okay so first I will 

create a a normal class because only interfac is no no use okay we have 

to create a class also so let's create a class directly and here I will name it as 

interface demo and main method also I'm taking so this is the interface and along with the 

method let's keep this is a class let's keep this class one side now I will create one interface 

just like a class we can also create an interface so by using interface keyword interface and 

I give some name to interface called shape okay now observe this what is interface contains 

suppose if I create a variables by default those variables are what final and static variables okay 

just observe here I'm just creating one variable inter length equal to 10 see as soon as you create 

a variable turn into holic so this is a static variable this is also final variable you no need 

to write a static and final keywords you no need to write anything like this okay by default that 

as soon as you created a variable that is a final and a static variable remember this final and also 

static variable similarly I'm creating one more variable in width equal to 20 this is also final 

and a static variable so by default the variables are meth variables are final and stating now what 

type of methods it is allowed to create three types of methods allowed one is abstract methods 

default methods static methods so abstract methods doesn't have any implementation but default and 

static methods we can have implementation okay from java 8 onwards static methods and default 

methods are allowed but in the old version of java initially only abstract methods are allowed so I'm 

creating one default method observe very carefully I'm creating one method here void Square just 

like a normal method I created it is giving an error why it is giving an error because we this is 

normal method we have started implementation here as soon as you put this curly brace implementation 

is started so implemented method are not allowed in interface we cannot implement the methods in 

the interface only the Declaration is allowed but here as soon as you started the cly braces 

I'm implementing this okay suppose I'm writing some message system. out. print and okay I can 

say this is this is a square see I have already implemented this method so these type of methods 

are not allowed in the interface then what we can do and also by default whenever you create a 

method that's a public so we have to make it as a default then this implementation is allowed so 

the default methods are allowed in interface okay and uh we can also create an abstract method how 

to create an abstract method return return type name of the method and then simply backet and 

semicolon this is called abstract method there is no implementation okay this is called abstract 

method so the interface allowed abstract methods default methods what is a default method any 

method which is having default keyword in front of it which is called default method the default 

methods are allowed and one more type of method is what static methods also allowed so let me 

create one more method void rectangle this is implemented implemented methods not allowed now 

I can make it as a static static so then it is allowed so inside this I can just write something 

is implementation so this is rectangle this is static method okay and this is default method 

so for this circle is abstract method there is no implementation so now when you create 

an interface variables are by default final and static and it is allowed three types of 

methods abstract methods default methods and static methods abstract methods doesn't have any 

implementation which is also called unimplemented Methods whereas default methods and starting 

methods we can have implementation so this is the definition as per the interface okay now who 

will implement this abstract Methods at least we need one class one class we should implement this 

interface by using any other class so now come to the main class so this is the class this class 

can implement this interface so now what I will do is here I will write implements implements 

shape okay so this particular uh interface I'm trying to implement as soon as you say implements 

a shape every whatever is belongs to the interface which will come into this particular class 

okay now what is this class contains class contains variables final and static variables 

one abstract method one default method one static method everything will come into this class now 

this class giving an error if you put this cursor here what it is saying the type interface demo 

must implement the inherited abstract method shape do Circle that means whenever you say 

Implement interface whatever methods are there in the parent interface must be implemented in the 

child class otherwise it is not allowed so why we are trying to implement this interface because 

the interface contains some abstract methods so definitely we have to implement this method 

in the child class now let us try to implement that method so at the time of implement same 

return type same method name and now we need to start implementation okay so in the above 

in the interface we are not implementing but here we are trying to implement so void Circle 

same method name void Circle and bracket here we have to implement so now implementing 

this system. P this is circle abstract method okay now I have successfully implemented 

whatever abstract method I defined in the parent interface which is implemented but still it 

is giving an error previously it was giving an error here after implementation now it is 

started giving an error can anyone know why it is giving an error here even though 

if you have implemented same method is got implemented in the child class why 

it is giving an error here can anyone guess okay so yes I told you one important point the 

suppose if you create any method like this in the class what is a default access modifier 

for this method what is an access modifier we'll allocate to this method default okay so 

this access modifier is default if you're not specifying anything default so similarly 

here what is an access modifier for this method because this is implemented in the class 

right if I don't specify any access modifier if I don't specify any access modifier here 

what is the default access modifier for this again you're not just understand this let 

us take a class in the class I have created some method I have not specified any access modify 

so which access modifier will allocate to this method in class I'm asking which access modifier 

will allocate to this method if I don't specify any access modifier default okay so this method 

is a default method because we are not specified any access modifier it is default in the class 

so here this method is got implemented I have not specified any access modifier so which one 

will allate by default default access modifier we allocate because this is the class right 

in this class we have written some method and if I don't specify any access modifier default is 

allocated this is the default method now okay but this method is coming from what parent interface 

in the parant interface what is an access modifier for this abstract method public got my point 

so in the parent interface this method is what public but as soon as you implementing here this 

becomes default earlier it was public now it will become default so when you put the cursor here 

it is clearly saying cannot reduce the visibility of inherited method from shape cannot reduce the 

visibility reducing visibility means nothing but what public is a higher level modifier default 

is a lower level modifier public is having more scope to access default is having very less scope 

to access so which was is higher public or default public is higher modifier but what we are trying 

to do here if I don't specify anything that is a default but what it is previously it is public 

previously it was public now I'm making this as a default so public to default why what we are 

doing here we are reducing the access it is not possible we cannot reduce the access whatever is 

access modifier is there in the parent interface same access modifier should be there at the 

time of implementation that's what my point okay if you don't specify anything default it is 

taking default is what lesser than public so it is giving an error so what is the solution for 

this what is the solution for this yes whenever you are trying to implement abstract method you 

have to specify public keyword don't forget this okay whenever you're trying to implement any 

abstract method from the interface you should specify public explicitly okay that is the point 

we have discussed here methods in interface are public okay whenever you're implementing those 

abstract method in the class you have to make them as a public okay is this point clear 

everyone how to implement abstract method in the child class what are the necessary steps 

you have to take while implementing the methods okay fine so what about the two methods this is 

implemented now Square method rectangle method by default will come to the class and they are 

also having implementation so we don't need to bother about that so now tell me how many methods 

are there in this particular class interface demo class how many methods are there totally how many 

methods are there in the interface demo class yes three methods only right so these are the three 

methods we are implementing by using interface so abstract method we already implemented and rest 

of two methods also come to this class totally three methods are there now let us try to access 

them by creating an object so now how to access those methods so all three methods are belongs to 

this class can we create an object of this class and access all three methods yes can we create an 

object for this class and then we can access all the methods yes let me create so interface demo 

for this I'm creating an object just ID obj new interface demo is this correct or not I can create 

an object reference here object I'm creating and object reference variable is also same got 

my point when I creating an object I'm using the same class and also I'm when I creating the 

variable also I'm using the same class we already know this so by using this object we can access 

methods right so let us try to access ID obj Dot Circle what type of method it is abstract method 

which we have implemented in the CH class perfect now ID obj dot ID obj dot uh Square what type of 

method it is this is default method right here we are calling abstract method by using an object 

here we are calling default method by using an object okay and rectangle is what rectangle 

is what static method static methods we can call directly by using a class right by using 

a direct class we can call static method object is not needed right so how to call shape method 

simply can say shape that's it got my point Sorry rectangle because this is what static method 

so this static method is belongs to what this class as soon as you implement shape the static 

method is also belongs to what interface demo so without creating any object I'm directly calling 

the method so still it is giving an error why it is giving error because we can directly access 

the static methods from the class right in the last classes we discussed static methods 

static variables are common common across everything so we can access static methods and 

static variable directly by using a class but here because the class is also part of the same 

file I'm not specifying any class it is giving an error why because actually this rectangle 

method is belongs to the class actually this rectangle method is belongs to what interface 

shape interface it is belongs to after that we are trying to get everything into the class 

now this rectangle is belongs to the class right but this is not direct method from this 

class got my point this rectangle method we have not directly created in the class if you 

directly created this method in this class we can directly access like this without creating an 

object without specifying the class name but this method is not directly created in this class we 

get it from the shape interface indirectly we get it so we have to specify the interface name not 

the class name shape. rectangle this is the way we can access static methods directly by using 

interface name we can get it just if the static method is created in the class directly then 

we can access the static method directly from the class or if the static method is created in 

the interface we can access it directly by using interface that's my point understood everyone 

so the static method can directly access from interface okay this is a scenario one 

scenario one so we created an object of the class through the class abstract method 

default method we can directly access this is sorry abstract method default method we able 

to access through the object but when you're trying to access static method we directly use 

interface name interface name do static method same rule is applicable here static methods 

we can directly access by using a class name itself when if the static method is created 

in the same class but here the static method is created in the interface so we can access 

static method directly by using interface name so this is the scenario is this clear everyone 

we created an object for the child class then we are able to access everything that is a point 

right now come to the next one scenario 2 just observe very very important I'm just commenting 

this okay now in the scenario I will show you the different thing the first scenario we have 

created an object for the class even reference variable is also class class type variable we 

created now I will create the object for the class that we can hold interface variable 

right I told you this point we can create object reference for interface but we cannot 

instantiate we can create object reference for interface shape sh equal to new shape this is 

not possible this is instantiation process this is object creation process so for the interface 

we cannot create an object but reference variable we can create but without able to create an 

object why this reference variable is needed because even though if you're not able to create 

an object for the interface still we can create an object for the class which is implemented the 

same interface so here I can specify the class name instead of interface name so now this will 

create an object for what class and this class object we can store in the interface variable 

why we are able to store because this class is implemented this interface that is the reason 

the variable of interface can hold the object of class which is implemented the interface 

is this point clear to everyone is there any confusion so the object of CH class can 

hold into the variable of interface here what we have done the object of the class we 

have stored in the object of same class but here the object of the class we are storing 

into the variable of interface why it is possible because this class is implemented this 

interface itself there is a connection between this got my point so the object reference 

variable we can create but object we cannot create for the interface interface object we 

cannot create for the interface the purpose of interace is totally different we cannot compare 

with the class okay now with this variable what are all things we can access now observe very 

carefully I'm saying sh dot I want to access abstract method what is the abstract method is 

what circle is it possible or not is it possible or not yes obviously so the abstract method we 

can access through the object Now by using sh Square what is square here square is a 

default method circle is what abstract method we are able to access square is what 

default method we are able to access what about static method what about static method 

static method we can directly access with interface there is no object required right 

so directly you can say shape do rectangle just like this earlier also we have done 

the same thing so here static method can directly access from interface okay so 

now when I run this you will able to execute okay so this is a scenario to in the 

first scenario the object is created for the class and variable is also same type and in the 

second scenario object will be created for the class but the variable type is interface that 

is a reference so the object of child class can hold into the variable of parent class this is 

the ultimate Point here so is this example clear everyone so now if you go to the points 

we covered everything so an interface is a blueprint of class in interface contains 

only final and static variables okay and interface contains abstract methods and 

also allowed default and static method from java 8 abstract method is Method contains 

a signature but there is no body unimplemented method also we have discussed when we need 

abstract methods to create by default all methods or interface are public and interface 

supports a functionality of multiple interface inter inheritance we will see this point point 

in the next example and we can Define interface with interface keyword and class extends another 

class and interface extends another interface but a class implements an interface this also in 

the next point we will see in the last Point can we uh we can create an object reference 

for the interface but we cannot instantiate interface yes so after extending after 

implementing this interface into the class here if you want to create any other new 

methods you can add no problem okay suppose uh in the interface I have a square circle 

rectangle now in this particular class I will introduce a new method okay new method I 

will introduce let's say void triangle this is the normal method it's not a default method 

not a not a public method this is a default method because we not specified any access 

modifier default will be taken not static not abstract so here this is a own method 

which we created in the class so here this is triangle okay you can create your own method 

in this class and this method is not belongs to interface now can we access this method here 

just observe it's commenting so I created this object for the same class I'm able to access 

abstract method default method static method and Now by using this ID OJ can we access 

triangle method or not yes obviously we can access because this method is belongs to the 

same class right so we are able to access so triangle we are able to access okay suppose if 

you create a object for the class but the variable type is interface in this particular CL can we 

access here sh dot triangle can you access or not sh. triangle you cannot access you 

cannot access even though you created this object for the class you're holding it 

into interface variable so in this interface there is no triangle method right there is 

no triangle method so you can't access sh dot triangle so this is giving an error this is 

giving an error so what is giving an error the method triangle is undefined for the 

type shape so this method is not available in the shape interface so that is the reason 

we are not able to get even though we created an object for the class still we are able 

to hold it into the interface variable so through that interface variable we are 

trying to access triangle this triangle is actually belongs to this class not with 

the interface that's the reason we we cannot access okay everyone is able to understood this this example all points are clear now I will show you how to achieve multiple 

inheritance using this interface concept sh. rectangle sh do rectangle is what 

basically a static method right that static method you can access everywhere directly using 

shape interface you can access directly by using object also you can access everywhere you can 

access because that is rectangle is a static method rectangle we created in 

the interface that is static method and whenever you implement that 

is also belongs to the class so static method static variable always try to access 

directly there is no object is required for them yes okay directly you can try to access them 

can we access variables in interface demo which is not declared in the shape okay can 

we access variables in interface demo which is not declared in shape using shape reference 

yes variables also you can access so basically what is type of variables are static and final 

right so static by default static is there so again you can access these variables directly 

by using interface name you don't need any object for them you can directly access the 

static variables directly by using interface wherever you see static don't think about the 

object forget about object access directly from the inter interface name all the variables 

okay so for example here I want to capture the values of variables simply you can say shape 

dot you can see length and width you're able to get shape do length into shape dot width 

I'm just calculating something then you can print something shape do length into 

shape do width length and width are what static variables so that's the reason we able to 

directly access it so accessing static variables directly okay you can also do like 

this if you have a variables static because by default they are 

static so that's the reason you can directly access you don't need 

to access from the object object is not needed yes so if you want to declare any new 

variables in this particular uh interface demo class you can create your own variables no 

problem you can create your own variables in this and those variables you can access again 

through the object of this class not from the shape got my point see here we have created 

one new method called triangle all right so that method we're able to access only through 

the object of the class but when you create a variable for interface here we are not able 

to access got my point why we are able to access why we are not able to access triangle 

because this triangle is purely related to this particular class similarly if you create 

variables also in this class those variables we can directly access from the object just 

like a triangle method but you cannot access them by using interface variable same concept 

is applicable for variables also just like a method so you can create a variable like this 

suppose uh in this interface demo you can create suppose if you create a variables here again 

that we cannot directly access from the main method only through object you can access 

let me create some variables for example uh here I'm creating some X comma y okay two 

variables I created okay let make it as 100 and this is 200 and these variables are belongs 

to what class class variables and this triangle method is also belongs to the class so these 

are all ultimately belongs to what class so here by using this object we're able to access 

rectangle right same thing by using this object ID obj okay we can access X and also I'm just 

adding those two numbers ID obj do y so we can access like this can directly access just like 

a method we can also directly access variables okay but here it is fine but when you come here 

triangle method we are not able to access why because triangle is related to interface through 

this s we cannot triangle is sorry triangle is purely related to the class interface demo class 

so this is the new method which we have created this is not belongs to interface so we are not 

able to access it same thing here when you're trying to access this one uh same variables 

I'm trying to access this and instead of object I'm directly saying sh sh is a variable 

of interface right so when I say sh we cannot access it we cannot access this why because 

this X and Y is belongs to the class but not interface so guys I understood any confusion here so don't go beyond that just practice only 

this much and again you will be confused yeah so now let us see how can we Implement multiple 

inheritance using interface that is the main objective right so class we cannot achieve 

but interface we can achieve Okay so so let me show you a scenario now let us say I have an 

interface called i1 another interface called I2 these two interfaces I'll Implement by using a 

class so what type of inheritance it is there are two parents one child two parents one child 

so multiple inheritance right so now we will Implement that the same type of inheritance we 

will Implement so i1 I are the parents they are interfaces okay now in day 16 I will create new 

interface instead of class I can directly create an interface also you can find one option called 

interface so let me take this interface here we have to provide the interface name I'm just 

giving i1 and simply say finish so now it is directly create an interface okay in interface 

uh in this i1 I will Define some variables and methods I will create one variable in Tex equal to 

100 and by default this variable is what final and static and I will also create uh two methods 

one is uh void M1 and this is what this is uh abstract method okay abstract method but now 

let Let It Be There so this is the implement this is the interface one now similarly I 

will create another interface create new interface I'll name it as I2 and in this also 

I will create the same one variable and one method okay in I2 I will create one variable 

let's call it as Y into y 200 and then M2 this is also abstract method so now I have created 

two parents i1 is one parent I2 is another parent both are interfaces they're having 

one variable and one method now these two interfaces I can Implement by using one single 

class which is child class so for that I'm creating another class new class I will call it 

as a C1 C1 and here I need main method click on finish okay just observe okay so this is one parent i1 is one 

parent I2 is another parent now C1 should Implement these two parent so what we can do 

now in the C1 I can say implement right so we should not say extends here implements two 

interfaces we have to implement so implements i1 comma I2 you can specify n number of 

interfaces it is allowed but in case of extends it is not allowed only one class we 

can extend but here Implement allowed multiple interfaces so now C1 implements i1 and I2 as 

soon as you say implements i1 and I2 C1 must Implement abstract methods which are coming 

from i1 and I2 so M1 is one abstract method coming from i1 another one M2 coming from 

I2 now we need to implement those methods in the class so let us try to implement M1 in 

the C2 class or C1 so how to implement void M1 sorry void M1 right so inside this uh this M1 method I'm 

trying to access the variable directly so I can say because I can have X right so that 

X I can directly access I'm just trying to print the x value so whenever you are 

implementing this M1 you must specify the public access modifier right because 

this is a default method earlier it is a public method in the interface so it should 

be public so we have implemented now another method public void M2 M2 is coming from what I2 

interface so here also I'm trying to access y value okay so now we have implemented two 

methods M1 and M2 which are coming from i1 I2 interfaces this is X and this is y okay white is giving an error so why cannot be resolved as a variable 

okay sorry it is a uppercase okay so now we are able to access everything M1 M2 is implemented 

so now come to the main method how can we access these methods through the object through the 

object so let us create an object for C1 class C1 C1 obj equal to new C1 so now by using this 

E1 obj I can access M1 then by using C1 obj can access M2 so when I execute this will get the 

values of X and Y okay now this is an example for multiple inheritance so i1 is one parent I2 

is another parent so these two interfaces we have implemented by using one child class implemented 

methods and we are able to access this is called multiple inheritance now I'll tell you one more 

type just observe this is i1 interface this is I2 interface these two have implemented by using 

C1 class okay now suppose I have another class let's say call a C2 class along with these two I2 

parents I have another parent but this is class this time it is a class I want to get that also 

along with these two interfaces implementation whatever is there in the CCL class whatever is 

implementation variables are there in the C2 class I want to get them into C1 class then 

how it is possible so here i1 and I2 we use what implements for class two class what we need 

to use extends now can we use the combination of implements and extends yes okay but the first 

we have to do extend then we we have to use implements first extends then implements this is 

the approach okay now we will try to implement this see I will create another class another 

parent I'll call it a C2 okay C2 and take this class so in the C2 class I will create one 

variable inter J equal to 300 100 also I will create one method here we can have implemented 

methods M3 and here I'm directly printing the value of Jed right now this is the class so now 

I have already implemented i1 and I2 now I want to extend C2 how to extend the C2 first we need to 

extend here C1 extends C2 followed by implements so extend keyword allowed only one class and after 

that you can Implement n number of interfaces okay now by using this C1 obj we can access 

everything from C2 also so let me just call C1 C1 obj dot what is that method name M3 so this is 

actually coming from the C2 class you can access it okay so this is called multiple inheritance 

multiple inheritance means multiple parents one child you can have n number of parents if they are 

interfaces but if it is a class there is only one parent allowed so we can write like this first you 

can do extend Then followed by implements extends allowed only one class implements allowed 

multiple interfaces this is called multiple inheritance which we can achieve through interface 

okay now now I'll tell you one more thing we have something called Hybrid inheritance that is 

another type of inheritance we have understood single inheritance one class to another class 

this is called multi-level inheritance and this is called hierarchy inheritance one parent M 

multiple things and this is called multiple inheritance this is hierarchy this is multiple 

right multiple parents one child here one parent multiple CH if you combine these two you will 

get Hybrid inheritance for example one parent to two Childs again for these two Childs there 

is one child sorry for these two again there is one child so this is called Hybrid inheritance 

Hybrid inheritance so how can we achieve this so anyway these are the two parents we have to 

implement using this class so these two should be interfacing say and this can be a class then 

how can we achieve this you guys can think how can we achieve this Hybrid inheritance how can 

we write this statement let us assume this is i1 this is I2 this is C2 this is C1 okay now you 

tell me how to write this statement for Hybrid inheritance see the ultimate goal of this is 

what whatever is there in the C2 whatever is there in i1 and I two everything we should get 

into the C1 class right C1 class we should get this is the grandchild of everything that is 

our ultimate goal so first we will get these two interfaces Implement by using C1 and we 

can extend C2 directly from C1 to C2 C2 to C1 so c22 interface is not possible this 

is is not possible Right class interface class interface not possible right so what 

we can do now C1 can extend C2 directly and implements i1 and I2 same thing we have done 

right same thing we have done here so this is also Hybrid inheritance if you don't have 

this class only if you implement i1 i1 and I2 that is multiple inheritance and again if you 

added one more class additionally here this is Hybrid inheritance so hybrid is nothing 

but what hierarchy plus multiple inheritance hierarchy plus multiple if I look at here this 

above portion is hierarchy the lower portion is multiple the combination of hierarchy and 

multiple is called Hybrid inheritance so that we have achieved by adding another class okay 

so this is how we can work with the interface concept so is this clear everyone so what is 

an interface how to create an interface what interface contains and how to implement 

interface by using a class and how can we achieve multiple inheritance using interface 

so we have seen all these points now final step we will compare interface with abstract class 

so whatever we have achieved through interface same thing we can achieve by using abstract 

class also but there are some differences are there so let us see what are those differen 

what is an abstract class just like a normal class abstra class just we put abstract keyword 

if it is a normal class we create a class like this class test this is a normal class it is 

allowed to create static methods non-static methods okay all the variables and everything 

we will able to create in the normal class if it is a abstract class suppose in front of this 

class if I create an abstract keyword then this class class becomes the abstract class whenever 

the class becomes abstract class here we can create abstract methods okay and if normal class 

not allowed abstract methods only abstract class can allow abstract methods so here you can create 

any method which is abstract method but again you have to write abstract keyword in front of the 

method abstract keyword must be specified if it is a class but in interface we are never used 

this keyword have you used anywhere abstract keyword somewhere in interfaces or anywhere 

no we just created a method like this this is abstract method but in case if you want to create 

an abstract method in the class that class should be abstract class that in front of the method 

we have to specify the abstract keyword okay that's a major difference now let us see the 

differences other differences between abstract class and interface so interface Works more 

efficiently especially in the data abstraction so let us finally compare interface abstract 

class inter prospective important but in the real time most of the time we prefer to use 

interface only okay so let us compare uh these two now the first point because you already know 

interface you can easily understand abstract class when I create an abstract class can have abstract 

as well as non-abstract methods also in abstract class we can create abstract methods as well 

as non-abstract non-abstract methods in the sense normal methods implemented methods also 

we can create but in interface abstract methods allowed implemented methods are not allowed if 

you want to implement those methods should be default or static methods if I don't specify 

default and static definitely they should be only abstract methods right so which one 

is more abstract here abstract class or interface abstract class allowed abstract as 

well as non-abstract means unimplemented or implemented methods also allowed but interface 

implemented methods are not allowed so interface is more powerful than abstract class that's the 

first point abstract class have abstract as well as non-abstract methods whereas interface have 

only abstract methods if you want to Implement they should be default and static methods but 

non abstract methods you cannot create now the second Point abstract class doesn't support 

multiple inheritance means suppose uh this is one abstract this is one abstract class this 

another as class we cannot get it into one class so those two parents cannot be classes it can be 

normal class it cannot it can be abstract class cannot be two parents so multiple inheritance 

we cannot ACH achieve by using abstract class only through inheritance we can achieve multiple 

inheritance third Point abstract class can have final non-final static non-static all types 

of variables we can create but in interface allowed only static and final variables I hope 

this point is clear in the abstract class all types of variables we can create but in interface 

is by default the variables on static and final but in abstract class if you want to create a 

final variable if you want to create a static variable you have to specify the keywords final 

static these keywords explicitly you have to write but in case of interface you no need to write 

those keywords also by default the variables are static and final that's the third difference 

fourth difference abstract class can provide the implementation of interface Okay so suppose if we 

have an interface the interface we can Implement by using a normal class right normally so the 

interface can also Implement by using abstract class so interface to abstract class also we 

can use implements abstract class can have implementation that's the reason it is possible 

okay imp interface can also implemented by using abart class just like a normal class that's the 

point AB class can provide the implementation for interface but inter can't provide implementation 

of abstract class vice versa is not possible why abstract class contains implementations but 

interface doesn't have any implementations so class to interface not possible but interface 

to class it is possible we already covered this point earlier now the next Point fifth point the 

abstract keyword should be used to declare the abstract class but an interface keyword used to 

declare the interface we already know this now the sixth Point abstract class can extend another 

class another Java class and Implement multiple Java interfaces see this abstract class can extend 

another Java class suppose I have one class normal class this can be extended into abstract class 

here extends keyword work class to class even though it is an abstract class class to class only 

right extend so abstract class can extend another Java class and Implement multiple Java interfaces 

i1 I2 is there so these two also can Implement in the abstract class so one class we can extend 

multiple interfaces also we can Implement by using one abstract class this is also possible 

but an interface can extend another Java interface only interface to interface we can only do extends 

but not implementation seventh point an abstract class can be extended using extend keyword 

obviously we already know that but interface can be implemented using implements keyword next 

Point Java abstract class can have class members like private protected and everything see this 

in abstract class we can create methods with the different access modifier all kinds of access 

modifiers allowed private public protected default all kinds of access modifiers allowed 

for those methods in abstract class when you come to the interface all methods are public only 

only public is allowed okay and in abstract class we can create the methods with any type of access 

modifiers but in interface everything is a public now last Point how to create abstract class we 

use this keyword abstract class class name and the method in front of the method also we have to 

specify the abstract keyword but in interface you no need to write abstract keyword anywhere else 

so by default this interface is allowed abstract method this is your abstract method so these 

are the differences between abstract class and interface okay so just remember these points 

interview prospective it will be useful but in the implementation whenever you want to achieve 

data abstraction we always prefer to use only interface okay even s a web driver itself is an 

interface after that the web driver interface is implemented by using different classes 

Chrome driver class Firefox driver class okay Edge driver class for every browser there are 

different classes they have created and those classes are implemented same interface which 

is web driver web driver itself an interface So based on this concept the whole web driver 

selenium web driver component is developed for automation okay so again that time I will repeat 

how web driver they have created how the classes are implemented by using web driver because if 

you understood this concept interface you can easily understand that right so this is all about 

multiple inheritance we can achieve with interface concept and interface is a concept through which 

we can achieve data abstraction that is a concept okay so we'll stop here for today's session and 

tomorrow's session we'll continue with another concept so with this we have 

successfully completed with object oriented programming Concepts so 

what are the objectoriented programming Concepts so far we covered let us list out here oops Concepts can tell me can anyone 

tell me one by one first class then order object then after that polymorphism after 

that encapsulation encapsulation then inheritance then data abstraction these 

are the six Concepts which are belongs to object oriented programming so class and 

object is related methods are belongs to class now polymorphism we can achieve 

with what polymorphism we can achieve with what overloading again we have overloading 

Constructor overloading method overloading one thing can have many forms now encapsulation 

we can achieve with what sets and gets inheritance overriding overriding comes Under 

The Inheritance concept and data abstraction we can achieve with what interface 

or abstract class okay so these are the objectoriented programming Concepts 

interface comes under data abstraction or inheritance data abstraction data abstraction 

and also it will support inheritance multiple inheritance okay one class we can extend into 

another class it's called in inheritance concept you can apply for classes as well as interfaces 

inheritance concept is applicable for classes as well as interfaces okay so in the next classes 

we will discuss some more Concepts like access modifiers private public protected default 

when we have to use how we have to use and uh then we have to discuss about exception 

handling and then we have something called collections so these are the concepts we will 

discuss in the next two to three sessions and then we will finish it okay so I'll stop here for 

today's session tomorrow we will continue that

Need a transcript for another video?

Get free YouTube transcripts with timestamps, translation, and download options.

Transcript content is sourced from YouTube's auto-generated captions or AI transcription. All video content belongs to the original creators. Terms of Service · DMCA Contact

Session 16- Java OOPS Concepts - Data Abstraction | Inter...