Sunday, 11 August 2013
JAVA: Keyword: abstract
Do you like this Article?
abstract: | 
When a class contains any abstract method, it must be declared as abstract.
An abstract class cannot be
final.An abstract method cannot be
final, static nor native.
Code:
package com.interview.question.java;
abstract class SampleAbstractClass {
  /**
    *
    * Sample abstract class.
    *
    * @author http://interviewquestionjava.blogspot.com
    *
    */
      // Sample abstract method.
      public abstract void sampleabstractmethod() ;
      public void sampleNormalMethod(){
            System.out.println("SampleAbstractClass.sampleNormalMethod()");
      }
}
public class TestAbstractClass{
      /**
    *
    * Sample class to call SampleAbstractClass.
    *
    * @author http://interviewquestionjava.blogspot.com
    *
    */
      public static void main(String[] args) {
            SampleAbstractClass objSampleAbstractClass = newSampleAbstractClass() {
                  @Override
                  public void sampleabstractmethod() {
                        System.out
                                    .println("TestAbstractClass.main(...).new SampleAbstractClass() {...}.sampleabstractmethod()");
                  }
            };
            objSampleAbstractClass.sampleabstractmethod();
      }
}
Output:
TestAbstractClass.main(...).new SampleAbstractClass() {...}.sampleabstractmethod()
Subscribe to:
Post Comments
                          (
                          Atom
                          )
                        
Popular Posts
- 
public - public means everyone can access it.That means it's in global scope. As, main method is called by JVM [ Java Virtual Machine...
 - 
throw is used to throw an exception in a program, explicitly . Whereas, throws is included in the method's declaration part, wi...
 - 
Singleton in one of the most popular yet controversial design pattern, in the world of object oriented programming. It's one of t...
 - 
Web Container / Servlet Container / Servlet Engine : In J2EE Architecture , a web container (also known as servlet container or ser...
 - 
ORM ( Object Relational Mapping ) is a programming concept of a mapping between Object Oriented Programming and Relational Database ...
 - 
In Java Programming Language , we must declare a variable name and type, before using it. The data type of a variable defines the th...
 - 
Vector : It's synchronized. It's slower than ArrayList. It's generally used in ...
 - 
Program compiles. But at runtime throws an error “NoSuchMethodError”.
 
 
6 Responses to “ JAVA: Keyword: abstract ”
1 September 2013 at 15:20
When a class is declared as an abstract, the class should have at least one abstract method.
I think this statement is WRONG..
6 September 2014 at 21:27
I like it thanks for sharing such a brilliant information, great blog
Picgrant Singapore 2014
27 March 2020 at 15:28
Great article with lots of useful information on Java Training in Chennai wonderful explanation on Java Courses.
Java Training Center in Chennai | Best Java Training in Chennai | Java Training Institute in Chennai
8 August 2020 at 21:52
Nice Post Dude
13 September 2021 at 19:25
Best article, very useful and explanation. Your post is extremely incredible. Thank you very much.
Visit us: Java Online Training Hyderabad
Visit us: Core Java Online Course
5 August 2022 at 13:00
This may be an issue with my internet browser because I’ve had this happen before.
Post a Comment