What is an abstract method and how to use it?
Introduction to an abstract method and information on how we can use it correctly?
An abstract method is special kind of method that we call as a unimplemented method. An abstract method can only be written inside an abstract class. This is a method which has no {} braces and no statements. It is just declared and we type a semicolon ; at the end of this type of method. We use this type of method in a very rare situations, especially when we want a method to be overridden and have no body itself. For example,
abstract class Example
{
// A normal method.
public void method1()
{
}
// An abstract method with no body.
public abstract void method2();
}
class MyClass extends Example
{
public void method2()
{
// This method will have to be overridden else a compile - time error will be thrown.
}
public static void main(String[] args)
{
}
}
In the above example we have a class named as Example and we have declared two methods in side it namely, method1() and method2(). The first method, which is method1(), is a normal method but the second method, which is method2(), is an abstract method. An abstract method has to be overridden in the class that extends the class, in which the abstract method is declared. Then we have created a class named as MyClass and we have overridden the method2() function and we have created the main() method in this class and this means that when the program execution starts that will first of all enter this method and this method is called the entry point of the program because this is the method that starts first of all.
Nothing Found!
Why not submit your own content? Signup here.
-
XA Transaction - Solution for Transaction More Than One Database | By H4d1 | in Programming
Have you ever think that it's too difficult for making database transaction in two different places (or databases) ...
-
Javascript functions for : trim, right trim, left trim, no Apostrophe, is Empty , is Digit , VarChar To Number , is integer , check Is Zero , Get Que | By xxris | in Programming
Javascript functions for : trim, right trim, left trim, no Apostrophe, is Empty , is Digit , VarChar To Number , i...
-
How to access and use a Window's command line | By MaxwellPayne | in Programming
Learn about the Window's command line in DOS and how to use it....
-
How to Learn to Program Your Computer | By dsj8760 | in Programming
This article is about learning to program a computer. It is a general article giving tips on how to learn about pro...
-
Jailbroken iPhones get RickRolled | By explorer | in Programming
First iPhone worm, attacks via SSH and does the classic rick roll gag on the user....
-
What is an XML Schema ? | By AmanDhiman | in Programming
Introduction to XML Schema and information on its advantages....
-
What is XML? | By AmanDhiman | in Programming
Introduction to XML and features of Extensible Markup Language....
-
How to create a free website ? | By AmanDhiman | in Computers
Information on how we can create a free website....
-
What is an animated image and how to create it ? | By AmanDhiman | in Software
Information on an animated image and the workings of an animated image....
-
What is a computer ? | By AmanDhiman | in Computers
Introduction to computer and information on the field that computer is being used in....







No comments yet.