Preview

ghhj

Good Essays
Open Document
Open Document
546 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
ghhj
Abstraction refers to the ability to make a class abstract in OOP. An abstract class is one that cannot be instantiated. All other functionality of the class still exists, and its fields, methods, and constructors are all accessed in the same manner. You just cannot create an instance of the abstract class.
If a class is abstract and cannot be instantiated, the class does not have much use unless it is subclass. This is typically how abstract classes come about during the design phase. A parent class contains the common functionality of a collection of child classes, but the parent class itself is too abstract to be used on its own.
Abstract Class:
Use the abstract keyword to declare a class abstract. The keyword appears in the class declaration somewhere before the class keyword.
/* File name : Employee.java */ public abstract class Employee
{
private String name; private String address; private int number; public Employee(String name, String address, int number) { System.out.println("Constructing an Employee"); this.name = name; this.address = address; this.number = number; } public double computePay() { System.out.println("Inside Employee computePay"); return 0.0; } public void mailCheck() { System.out.println("Mailing a check to " + this.name + " " + this.address); } public String toString() { return name + " " + address + " " + number; } public String getName() { return name; } public String getAddress() { return address; } public void setAddress(String newAddress) { address = newAddress; } public int getNumber() { return number; }
}
Notice that nothing is different in this Employee class. The class is now abstract, but it still has three fields, seven methods, and one constructor.
Now if you would try as follows:
/* File name : AbstractDemo.java */

You May Also Find These Documents Helpful

  • Satisfactory Essays

    [Type the abstract of the document here. The abstract is typically a short summary of the contents of the document. Type the abstract of the document here. The…

    • 508 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Modify the class declaration of the Employee class to specify that the Employee class is an abstract class…

    • 385 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Instructions: For this assignment, you are going to created an abstract class and then extend it.…

    • 495 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    9/11 Attacks

    • 488 Words
    • 2 Pages

    8. Definition tells what a term means and how it differs from other terms in its class.…

    • 488 Words
    • 2 Pages
    Good Essays
  • Better Essays

    I. A class is a collection of types and methods that all somehow work together.…

    • 939 Words
    • 4 Pages
    Better Essays
  • Satisfactory Essays

    using not only for this class but other classes as well. In the last presentation there were…

    • 466 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Into the Wild: Vocabulary

    • 319 Words
    • 2 Pages

    abstraction- the act of considering something as a general quality or characteristic, apart from concrete realities, specific objects, or actual instances.…

    • 319 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    The word “Abstract” should appear centered on the initial line of the page following the title page. Include the word “Abstract” without bold print, underlines, quotation marks, or italics. Double-space the abstract. Do not indent. On the line following the title, include a summary of the key points of the document. The abstract should appear as a single paragraph. The abstract should be between 150 and 250 words.…

    • 335 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    OOP Assigment 1 Sit 1

    • 4788 Words
    • 20 Pages

    Abstraction is used to simplify a complex object into a more generalised concept and its basic information and function of an object. It means looking at, for example, the idea of a mobile instead of a specific model and make.…

    • 4788 Words
    • 20 Pages
    Powerful Essays
  • Satisfactory Essays

    Hjgk

    • 292 Words
    • 2 Pages

    • Inter-dependent decision-making: Inter-dependence means that firms must take into account the likely reactions of their rivals to any change in price, output or forms of non-price competition.…

    • 292 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    This is a time when the child begins to learn logic and reasoning, which can increase cognitive functioning. This type of abstract thinking allows the adolescent to become more aware of the external world, such as attending school and socializing in the community. This is the “concrete” understanding that young people get when they begin to understand the world around them outside of the home.…

    • 1589 Words
    • 7 Pages
    Good Essays
  • Powerful Essays

    Ghghghj

    • 1445 Words
    • 6 Pages

    * Collection is grouping of classes that store elements of type Object and generic collection classes.…

    • 1445 Words
    • 6 Pages
    Powerful Essays
  • Powerful Essays

    3. Private Constructor:- In many situation, we may wish to define some utility classes that contain only static member such classes are never required to instantiate objects.Creating objects using such classes may be prevented by adding private constructor to the class.…

    • 550 Words
    • 3 Pages
    Powerful Essays
  • Powerful Essays

    Xcghj

    • 1470 Words
    • 6 Pages

    The FET Certificate in Corrections Services Learnership in DCS A rewarding opportunity to acquire the skills, knowledge, attitude and acceptable workplace behaviour required within the correctional environment while earning a stipend of R3 500 for twelve months.…

    • 1470 Words
    • 6 Pages
    Powerful Essays
  • Good Essays

    dfhgj

    • 4354 Words
    • 14 Pages

    4. Villefort, a prosecutor who knows that Dantès is carrying a letter addressed to Villefort's father; the old man is a Bonapartist who would probably be imprisoned by the present royalist regime were it not for his son's, Villefort's, influence. Villefort fears, however, that this letter might damage his own position, and so he makes sure, he thinks, that no one ever hears about either Dantès or the letter again.…

    • 4354 Words
    • 14 Pages
    Good Essays

Related Topics