Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

difference between abstract and interface

Interface 
1) Interface contains only abstract methods 
2) Access Specifiers for methods in interface
must be public
3) Variables defined must be public , static ,
final
4) Multiple Inheritance in java is implemented
using interface
5) To implement an interface we use
implements keyword

Abstract Class
1) Abstract class can contain abstract methods,
concrete methods or both
2) Except private we can have any access
specifier for methods in abstract class.
3) Except private variables can have any access
specifiers
4)We cannot achieve multiple inheritance using
abstract class.
5)To implement an interface we use implements
keyword
Comment

abstract class vs interface

Interfaces specify what a class must do and not how. 
It is the blueprint of the class.
It is used to achieve total abstraction. 

We are using implements keyword for interface.

Abstract=
Sometimes we may come across a situation
where we cannot provide implementation to
all the methods in a class. We want to leave the 
implementation to a class that extends it.
  In that case we declare a class
as abstract by using abstract keyword on method
signature.In my framework I have created my
PageBase class as super
class of the all page classes. 
I have collected all common elements
and functions into PageBase class and
all other page classes extent PageBase class.
By doing so, I don't have to locate very
common WebElements and it provides
reusability in my framework.
Also
1)Abstract classes cannot be instantiated
2)An abstarct classes contains abstract method,
concrete methods or both.
3)Any class which extends abstarct class must
  override all methods of abstract class
4)An abstarct class can contain either
  0 or more abstract method.  
Comment

interface vs abstract class java

an abstract class can have abstract and non-abstract instance methods while an interface can have abstract or default instance methods;
an abstract class can extend another abstract or regular class and an interface can only extend another interface;
an abstract class can extend only one class while an interface can extend any number of interfaces;
an abstract class can have final, non-final, static, non-static variables (regular fields) while an interface can only have static final variables;
an abstract class can provide an implementation of an interface but an interface cannot provide an implementation of an abstract class;
an abstract class can have a constructor and an interface cannot;
in an abstract class, the keyword abstract is mandatory to declare a method as an abstract one while in an interface this keyword is optional.
Comment

difference between interface and abstract class

Interfaces specify what a class must do. 
It is the blueprint of the class.
It is used to achieve total abstraction. 
We are using implements keyword for interface.

Basic statement we all know in Selenium is
WebDriver driver = new FirefoxDriver();
WebDriver itself is an Interface.
So we are initializing Firefox browser
using Selenium WebDriver.
It means we are creating a reference variable
of the interface and creating an Object.
So WebDriver is an Interface and
FirefoxDriver is a class.

Sometimes we may come across a situation
where we cannot provide implementation to
all the methods in a class. We want to leave the 
implementation to a class that extends it.
  In that case we declare a class
as abstract by using abstract keyword on method
signature.In my framework I have created my
PageBase class as super
class of the all page classes. 
I have collected all common elements
and functions into PageBase class and
all other page classes extent PageBase class.
By doing so, I don't have to locate very
common WebElements and it provides
reusability in my framework.
Also
1)Abstract classes cannot be instantiated
2)An abstarct classes contains abstract method,
concrete methods or both.
3)Any class which extends abstarct class must
  override all methods of abstract class
4)An abstarct class can contain either
  0 or more abstract method.  
Comment

interface vs abstract class java

Interfaces specify what a class must do. 
It is the blueprint of the class.
It is used to achieve total abstraction. 
We are using implements keyword for interface.

Basic statement we all know in Selenium is
WebDriver driver = new FirefoxDriver();
WebDriver itself is an Interface.
So we are initializing Firefox browser
using Selenium WebDriver.
It means we are creating a reference variable
of the interface and creating an Object.
So WebDriver is an Interface and
FirefoxDriver is a class.

Abstract Class
1) Abstract class can contain abstract methods,
concrete methods or both
2) Except private we can have any access
specifier for methods in abstract class.
3) Except private variables can have any access
specifiers
4)We cannot achieve multiple inheritance using
abstract class.
Comment

PREVIOUS NEXT
Code Example
Java :: how to get length of 2d array java 
Java :: comments java 
Java :: java tree traversal 
Java :: switch in java 
Java :: navigation bottom android 
Java :: android studio convert java to kotlin 
Java :: java startswith regex 
Java :: java design patterns 
Java :: java @override annotation 
Java :: java draw image 
Java :: hash map 
Java :: enum class in java 
Java :: java application 
Java :: java array 
Java :: set array length java 
Java :: java hashmap set value 
Java :: eclipse versioning .classpath 
Java :: android activity set action bar options 
Java :: how to change state of a Switch programmatically andoir dstudio 
Java :: Java Custom Annotations 
Java :: bluetooth chat example android client 
Java :: key caracter from code java 
Java :: spring secutiry urls redirecting 
Java :: Exercise. Create a simple Java program using array named SumOfArray.java that will accept an input of whole numbers or floating point numbers and will return the Sum result. The program must accept at least 5 numbers. 
Java :: arraycopy merging arrays 
Java :: how to write a perfect shuffle method in java 
Java :: constraint layout not matching parent in netsted scrollview 
Java :: java operations on classes 
Java :: setvisibility not working in fragment 
Java :: install the app from assest of other app 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =