Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

abstract class in java

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 such case we declare a class
as abstract.To make a class abstract we use key word abstract. 
Any class that contains one or more abstract methods is declared as abstract. 
If we don’t declare class as abstract which contains abstract methods we get 
compile time error.
  
  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

abstract class in java

/*Abstract class:
A class which is declared as abstract is known as an abstract class. 
It can have abstract and non-abstract methods. It needs to be extended 
and its method implemented. It cannot be instantiated.

*/

// Example of abstract class
abstract class A{}  
// Example of Abstract class that has an abstract method
abstract class Bike{  
  abstract void run();  
}  
class Honda4 extends Bike{  
void run(){System.out.println("running safely");}  
public static void main(String args[]){  
 Bike obj = new Honda4();  
 obj.run();  
}  
}  
Comment

abstract class in java

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

PREVIOUS NEXT
Code Example
Java :: java set 
Java :: why enable multidex android 
Java :: how to output in java 
Java :: Java Access ArrayList Elements 
Java :: uninstall java 
Java :: java print method 
Java :: print anything in java 
Java :: java access a file 
Java :: get all enum values java 
Java :: parcourir un string java 
Java :: draw circle with fill java 
Java :: how to change toolbar name in android studio 
Java :: how to find armstrong numbers in java 
Java :: Infinite While Loop Java Example 
Java :: android studio reg get float from numeric string 
Java :: how to put a string in gradle file and acce to it android studio 
Java :: A* shortest path algorithm 
Java :: java print a line seperate by space 
Java :: change short video to byte array android 
Java :: android text change java debounce 
Java :: Button loginButton = new Button(this); loginButton.setText("Login"); Button register Button = new Button(this); register Button .gettext("Register"); 
Java :: Java Enabling Assertions 
Java :: algorithm to know if a number is an integer 
Java :: Print Text Using Java 
Java :: maths.abs function in java 
Java :: maximum number from random number in java 
Java :: java system.out.println shortcut 
Java :: java csv compare 
Java :: final method and abstract method 
Java :: spring-boot-maven-plugin not found 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =