Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

Java abstract Modifier
Previous Home Next

The abstract modifier may be applied to a class or a method, but not to a variable. A class which is declared abstract cannot be instantiated .i.e. its object cannot be created because it is not fully implemented.

There is a relationship between an abstract class and an abstract method which is, if a class has one or more abstract methods, it must be declared abstract. A class may define abstract methods in any of the following ways:

  1. A class may have one or more abstract methods defined in it.

  2. A class might have inherited one or more abstract methods from its superclass, and has not provided implementation for all or some of them.

  3. A class declares that it implements an interface, but does not provide implementation for at least one method in the interface.

In above shown cases, the class must be declared abstract.But, if there is no abstract method in the class, it could still be declared abstract but in this case the class cannot be instantiated. Following code snippet will give a good idea about the abstract modifier,

 

Example


abstract class Shape              
// declaring an abstract class
{
 abstract void Area();            
 // an abstract method with no body
 void Printanything()             
	 // a simple method
  {
   System.out.println("hello!! Shashi Chaudhary @ r4r");
  }
}
Java Tutorialslass Rectangle extends Shape       
// defined a class which is inheriting Shape class
{
int length;
int breadth;
 Rectangle(int length, int breadth)
  {
   this.length=length;
   this.breadth=breadth;
  }
 void Area()                       
	 // implementing the Area() method defined in Shape class
 {
  System.out.println("The area of rectangle is given by :"+(length*breadth));      
  // displaying area of rectangle
 }
}
Java Tutorialslass Java Tutorialsircle extends Shape
{
  int radius;
  Java Tutorialsircle(int radius)
  {[an error occurred while processing this directive]
   this.radius=radius;
  }
void Area()                         
	// Implementing the Area() method defined in class Shape
 {
  System.out.println("The area of circle is given by :"+(Math.PI*radius*radius));    
  // displaying  area of circle
 }
}
Java Tutorialslass AbstractModifierExample
{
 public static void main(String args[])
 {
// Shape shp = new Shape(); /* will cause compilation error as Shape is defined abstract
     Rectangle objrect = new Rectangle(7,5);
     Java Tutorialsircle objcirc = new Java Tutorialsircle(7);
     objrect.Area();
     objcirc.Area();
     objcirc.Printanything();         
	 // accessing the  method defined in class Shape through Circle's instance
     objrect.Printanything();        
	 // accessing the method defined in class Shape through Rectangle's instance
 } 
}

A abstract class is some what opposite to the final class. A final class cannot be extended or inherited, whereas an abstract class must be extended, before it can be instantiated. An abstract class or an abstract method means itís not fully implemented .i.e if you want to use it, you have to implement it.

Previous Home Next