Abstract class and class

What is the difference between abstract class and class in java?

arcadesstuff wrote:
Abstract class: a class that contains at least one abstract method. As has already been mentioned, abstract classes need not contain any methods at all. Have a look at the abstract class you posted; it's still abstract, though it contains no abstract methods. Note that if one declares any method of a class abstract, the class itself must be declared abstract as well.
When you implement the abstract class Animal, you will have to write the code of those two abstract methods from above.Your example contains no abstract methods. Abstract methods must be marked with the keyword "abstract".
~

Similar Messages

  • Abstract method and class

    I'm a beginner in Java and just learn about abstract method and class.
    However, i am wondering what is the point of using abstract method/class?
    Because when I delete the abstract method and change the class name to public class XXXX( changed from "abstract class XXXX), my program still runs well, nothing goes different.
    Is it because I haven't encountered any situation that abstract method is necessary or ?
    Thanks!

    Yes - you probably haven't encountered a situation where you need an abstract.
    Abstract classes are not designed to do anything on their own. They are designed to provide a template for other classes to extend by inheritance. What you have build sounds like a concrete class - one which you are creating instances of. Abstract classes are not designed to be ever instantiated in their pure form - they act like a partial building block, which you will complete in a class which extends the abstract.
    An example might be a button class, which provides some core functionality (like rollover, rollout etc) but has an empty action method which has to be overwritten by a relevant subclass like 'StartButton'. In general, abstract classes may not be the right answer, and many people would argue that it is better to use an interface, which can be implemented instead of extended, meaning that you can ADD instead of REPLACING.
    Not sure if that helps.. there are whole chapters in books on this kind of thing, so it's hard to explain in a couple of paragraphs. Do some google searches to find out more about how they work.

  • What is the field and Table for "Batch Class" and "Class Type" in QM.

    Hi All,
    What is the field and Table for "Batch Class" and "Class Type" in QM.
    Thanks,

    Hi,
      For batch class the class type value is '023' . This you can find from KLAH table and the fileld for class type is KLART..
    And also all the data related to batch class are found in tables INOB, KLAH,KKSK and for the characeteristics of batch materials you can refer AUSP table.
    In INOB table, for batch class, you need to give 023 in KLART field and  value MCH1 in OBTAB filed.
    Please check this and let me know if this you need any more details?

  • Want to know more about class and class type and characters in batch determ

    hi ,
    i want to know abt class functionality and how it is related to batch mgt,means functions of class type , characters etc.
    ok thanks

    Hi ,
    Find the Class and Class Type for Batch Determination.
    Create Class for Batch Management
    Use
    In this step, you define two classes for use with batches. One class contains the characteristic LOBM_VFDAT: Expiration Date, and the other class with three characteristics:
    LOBM_RL: Remaining shelf life for batch,
    LOBM_LFDAT Batch determination delivery date, and
    LOBM_VFDAT Expiration date, shelf life.
    Procedure1.
    Access the activity using one of the following navigation options:
    Transaction Code: CL02SAP R/3 Role Menu     Installation ® Create Class for Batch Management
    2.Choose Create and maintain the necessary master data manually. The relevant data can be found in the file:
      Class     Class type     Description     Characteristic        Characteristic     Characteristic
    023_001     023     Products with Expiration Date     LOBM_VFDAT     
    023_002     023     Search class with expiration date     LOBM_RLZ     LOBM_LFDAT     LOBM_VFDAT
    Result
    The materials are later assigned to class 023_001 in the material masters. 023_002 is used in the batch determination search strategies for SD and PP/PI. 
    Regards,
    SAROSH

  • Class and class type based on inspection method

    Hi experts,
              I have a requirement in my script like this i have a inspection method. based on this inspection method i have to get class and class type. and from which table we can get this class and class type based on inspection method. please suggest the solution.
    Thanks in advance
    Thanks and Regards
    D.Ramesh

    Hi Sai,
    Have you tried Run Time Type services?  If you need to perform some interspection of a class, you can use one of two classes:
      CL_ABAP_OBJECTDESCR  or
      CL_ABAP_REFDESCR
    there are several methods you can use:
      Describe_by_Name
      Describe_by_Object_Ref
      describe_by_data_ref
      describe_by_data
    One of these should do the trick...it just depends on what situation you are in.
    Hope this helps!
    Quack

  • How can I find characteristic via class and class type

    hi all ,
    i have knew a class and class type , how should i find corresponding characteristic , i mean which table should i access .
    just like cl04 , if you enter class and class type , you should get some characteristics. these characteristics are what i want .
    please guide me .
    best regards
    Kevin

    Use
    INOB Table
    INOB-OBJEK = Material No.
    OBTAB = MARA
    Get CUOBJ and KLART(class type)
    KSSK   Table
    OBJEK = INOB-CUOBJ
    MAFID = 'O'
    KLART = INOB-KLART
    GET CLIENT
    from KLAH with KSSK-CLIENT
    Get class no.
    Call the function module CLAF_CLASSIFICATION_OF_OBJECTS with the following input parameters
    Class            =  
    Class Type     =  
    Object
    Object table
    U get Object Data table , it have ur Characteristic value from AUSP table.

  • Help required: Classes and class values for Func Loc

    Dear All,
    I have a requirement to get the classes and values associated with a functional location.
    Any idea how to get this data, as in IL03.
    Thanks,
    nsp.

    Hello nsp,
    You can try to check out the Function module ALM_ME_TOB_CLASSES to see how they fetched class, characteristics and their values.
    You can keep a break-point in this module and run MAM30_031_GETDETAIL and check how we can pass the appropriate values.
    However, above FMs are available from PI 2004.1 SP 14 of release 4.6c, 4.7 and 5.0.
    If you are in ERP 6.0, the FM's are available.
    Hope this helps
    Best Regards,
    Subhakanth

  • Me, Classes and Class rooms

    Hi,
    note : plz take your lunch on time :)
    I have a class called as Datastructure(one of my favorite classes), this class has methods:
    addKey(blah,blah...)
    containsKey(blah...)
    getKey(.....)
    getValue(.....)
    now I have to design a class clled Parameter, this class has to read patameters (from an ASCII file which does not change)into Datastructure so I extended the Datastructure class as
    .blah blah...Parameter extends DataStructure ....{
    Parameter's method readParameterFile reads the parameters and internally calles addKey method to fill in values. I am using few of the methods of DataStructure (containdKey, getKey,getValue.....).
    Some of DataStructure's methods are not required(or not used )here in Parameter. How should I not include them, or what ever I have done is correct.
    (one more thing) I want to call the Parameter's methods as Parameter.getKey()...(with out usingan object of Parameter)
    I am STILL new to Object Oreanted programming plz suggest me some good online matrial to learn how-to about designing Classes and learn about object oreanted designing

    note : plz take your lunch on time :)It will be another 23 hours in the current timezone.
    I am STILL new to Object Oreanted programming plz
    suggest me some good online matrial to learn how-to
    about designing Classes and learn about object
    oreanted designing
    http://java.sun.com/docs/books/tutorial/java/index.html

  • MIF: Split class and Class -- always alpha order

    When I use the MIF doclet with an XML book file that specifies classes to include in the book, and I use the <Split>class</Split> option, the doclet always puts the classes in alphabetical order, not in the "logical" order that I specify. I get the desired subset of the package, just not in the desired order.
    You can reproduce this with the sample XML files in the test/example-bookfile directory, if you comment out the <InsertAPIDoc> line, comment in the <Chapter>s that contains <Package>s and <Class>es, and fix the class names to match the actual sample source (e.g., SubClass, not SubClass1).
    The workarounds are:
    1. Use <Split>package</Split> instead of <Split>class</Split>.
    2. Use a separate FrameMaker book file, not the auto-generated one; this makes an automated process more difficult.
    I didn't find this in the bug database, though there is 4645280 about packages being "silently sorted".

    This is a known bug. I am surprised that it has not been filed. I will search for it again and file a new bug if I don't find it. A new version of the doclet that supports new J2SE 1.5 language features will soon be released. You can expect this bug to be fixed in that release.
    -Jamie

  • Question about Abstract Classes and Class Inheritance

    The semester is winding down, and the assignments are getting more complicated....
    Prof has given us a project involving both an interface and an abstract class. There's a class Person, then an abstract class Employee that extends Person, and two types of Employees (Hourly and Salaried) that extend Employee. The finished assignment is a type of payroll program that's supposed to be able to store both types of Employees and related info (name, salary, etc). One thing the prof suggested was to store both HourlyEmployees and SalariedEmployees in an array of Employees. But you can't instantiate an array of Employees directly, of course, since it's an abstract class.
    So is it possible to create an array of Persons, cast either HourlyEmployees or SalariedEmployees into Employee objects, and then store the Employee objects in the Person array? And if I do that, can I still use methods particular to the SalariedEmployees and/or HourlyEmployees once they are in the Person array? Or can I store SalariedEmployee and HourlyEmployee directly in an array of Persons, without having to cast them into anything else? (In that case, I'm not sure what the point of having the abstract Employee class is, though). Do they become just generic "Persons" if I do this?
    Thanks for any help!

    But you
    can't instantiate an array of Employees directly, of
    course, since it's an abstract class.Sure you can. You just can't instantiate Employee (the abstact class itself, as opposed to its subclasses) objects.
    Employee[] employees = new Employee[20];
    employees[0] = new HourlyEmployee();That should work.
    So is it possible to create an array of Persons, cast
    either HourlyEmployees or SalariedEmployees into
    Employee objects, and then store the Employee objects
    in the Person array?You could do that as well, but you shouldn't need to cast it.
    Given the type hierarchy you describe, an HourlyEmployee is a Person, so you should be able to assign an HourlyEmployee directly to a Person-valued variable.
    And if I do that, can I still use
    methods particular to the SalariedEmployees and/or
    HourlyEmployees once they are in the Person array?No. If the method doesn't exist in Person, then you can't call it on a Person variable, even if the method does exist in the class implementing Person.
    But if the method exists in Person, but is implemented and possibly overridden in HourlyEmployee, you can still invoke it, by just invoking the Person method.
    public interface Person {
      public void feed();
    public abstract class Employee implements Person {
      public abstract void hire();
    public class HourlyEmployee extends Employee {
    // then:
    Person persons = new Person[20];
    // add HourlyEmployees or SalariedEmployees to persons array...
    persons[0].feed(); // OK!
    persons[0].hire(); // NOT OK!

  • What is the diff b/w Abstract class and an interface ?

    Hey
    I am always confused as with this issue : diff b/w Abstract class and an interface ?
    Which is more powerful in what situation.
    Regards
    Vinay

    Hi, Don't worry I am teach you
    Abstract class and Interface
    An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.
    Edited by SASIKUMARA
    SIT INNOVATIONS- Chennai
    Message was edited by:
    sasikumara
    Message was edited by:
    sasikumara

  • Difference between abstract class and the normal class

    Hi...........
    can anyone tell me use of abstract class instead of normal class
    The main doubt for me is...
    1.why we are defining the abstract method in a abstract class and then implementing that in to the normal class.instead of that we can straight way create and implement the method in normal class right...../

    Class vs. interface
    Some say you should define all classes in terms of interfaces, but I think recommendation seems a bit extreme. I use interfaces when I see that something in my design will change frequently.
    For example, the Strategy pattern lets you swap new algorithms and processes into your program without altering the objects that use them. A media player might know how to play CDs, MP3s, and wav files. Of course, you don't want to hardcode those playback algorithms into the player; that will make it difficult to add a new format like AVI. Furthermore, your code will be littered with useless case statements. And to add insult to injury, you will need to update those case statements each time you add a new algorithm. All in all, this is not a very object-oriented way to program.
    With the Strategy pattern, you can simply encapsulate the algorithm behind an object. If you do that, you can provide new media plug-ins at any time. Let's call the plug-in class MediaStrategy. That object would have one method: playStream(Stream s). So to add a new algorithm, we simply extend our algorithm class. Now, when the program encounters the new media type, it simply delegates the playing of the stream to our media strategy. Of course, you'll need some plumbing to properly instantiate the algorithm strategies you will need.
    This is an excellent place to use an interface. We've used the Strategy pattern, which clearly indicates a place in the design that will change. Thus, you should define the strategy as an interface. You should generally favor interfaces over inheritance when you want an object to have a certain type; in this case, MediaStrategy. Relying on inheritance for type identity is dangerous; it locks you into a particular inheritance hierarchy. Java doesn't allow multiple inheritance, so you can't extend something that gives you a useful implementation or more type identity.
    Interface vs. abstract class
    Choosing interfaces and abstract classes is not an either/or proposition. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks.
    Abstract classes let you define some behaviors; they force your subclasses to provide others. For example, if you have an application framework, an abstract class may provide default services such as event and message handling. Those services allow your application to plug in to your application framework. However, there is some application-specific functionality that only your application can perform. Such functionality might include startup and shutdown tasks, which are often application-dependent. So instead of trying to define that behavior itself, the abstract base class can declare abstract shutdown and startup methods. The base class knows that it needs those methods, but an abstract class lets your class admit that it doesn't know how to perform those actions; it only knows that it must initiate the actions. When it is time to start up, the abstract class can call the startup method. When the base class calls this method, Java calls the method defined by the child class.

  • When we will go for an abstract class and when we will go for an interface?

    it's always some what confusing to choose an abstract class and an interface,can anybody post a suitable answer for this.

    jwenting wrote:
    with experience and the insight it brings, you will know which to use when.
    Without it, it can't be explained.
    More often than not there's no X OR Y anyway.It's fortunate that there are posters here who possess the insight and experience necessary to explain this. The principal differences between an abstract class and an interface are,
    1. An abstract class can carry implementation, whereas an interface cannot.
    2. An abstract class is singly inherited, wheras an interface is multiply inherited.
    So use an abstract class when the implementation it can carry outweights the fact that it cannot be multiply inherited That's the gist of it.
    The inheritance relationship where this happens is when the supertype is a general concept of which all potential subtypes are special cases. This is called a specialization (or sometimes a generalization) relationship. For example Apple and Banana are Fruit. Or Car and Bike are Vechicle. The Fruit and Vechicle supertypes are general concepts of which their subtypes are special cases. In this case make Fruit and Vechicle abstract classes because the subtypes will benefit from a shared implementation.
    If you don't have a clearcut specialization/generalization relationship make the supertype an interface. An example could be the Comparable supertype. The potential subtypes aren't supposed to be specializations of the Comparable concept, they're suppose to become Comparable (and make this property an integral part of their being). This is not a specialization/generalization relationship. Instead the supertype is intended to add character to the subtypes. The subtypes are unlikely to benefit from an inherited implementation. So make Comparable an interface.

  • Abstract Class and polymorphism - class diagram

    Hi,
    ]Im trying to draw a class diagram for my overall system but im not too sure how to deal with classes derived from abstract classes. I'll explain my problem using the classic shape inheritance senario...
    myClass has a member of type Shape, but when the program is running shape gets instantiated to a circle, square or triangle for example -
    Shape s = new circle();
    since they are shapes. But at no stage is the class Shape instantiated.
    I then call things like s.Area();
    On my class diagram should there be any lines going from myClass directly to circle or triangle, or should a line just be joining myClass to Shape class?
    BTW - is s.Area() polymorphism?
    Thanks,
    Conor.

    Sorry, my drawing did not display very well.
    If you have MyClass, and it has a class variable of type Shape, and the class is responsible for creating MyClass, use Composition on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it has a class variable of type Shape, and the class is created elsewhere, use Aggregation on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it is used in method signatures, but it is not a class variable, use Depedency on your UML diagram to link Shape and MyClass. The arrow will point to Shape.
    Shape and instances of Circle, Triangle, Square, etc. will be linked using a Generalization on your UML diagram. The arrow will always point to Shape.
    Anything that is abstract (class, method, variable, etc.) should be italicized. Concrete items (same list) should be formatted normally.
    BTW, the distinction between Composition, Aggregation and Dependency will vary from project to project or class to class. It's a gray area. Just be consistent or follow whatever guidelines have been established.
    - Saish

  • Abstract classes and methods with dollar.decimal not displaying correctly

    Hi, I'm working on a homework assignment and need a little help. I have two classes, 1 abstract class, 1 extends class and 1 program file. When I run the program file, it executes properly, but the stored values are not displaying correctly. I'm trying to get them to display in the dollar format, but it's leaving off the last 0. Can someone please offer some assistance. Here's what I did.
    File 1
    public abstract class Customer//Using the abstract class for the customer info
    private String name;//customer name
    private String acctNo;//customer account number
    private int branchNumber;//The bank branch number
    //The constructor accepts as arguments the name, acctNo, and branchNumber
    public Customer(String n, String acct, int b)
        name = n;
        acctNo = acct;
        branchNumber = b;
    //toString method
    public String toString()
    String str;
        str = "Name: " + name + "\nAccount Number: " + acctNo + "\nBranch Number: " + branchNumber;
        return str;
    //Using the abstract method for the getCurrentBalance class
    public abstract double getCurrentBalance();
    }file 2
    public class AccountTrans extends Customer //
        private final double
        MONTHLY_DEPOSITS = 100,
        COMPANY_MATCH = 10,
        MONTHLY_INTEREST = 1;
        private double monthlyDeposit,
        coMatch,
        monthlyInt;
        //The constructor accepts as arguments the name, acctNo, and branchNumber
        public AccountTrans(String n, String acct, int b)
            super(n, acct, b);
        //The setMonthlyDeposit accepts the value for the monthly deposit amount
        public void setMonthlyDeposit(double deposit)
            monthlyDeposit = deposit;
        //The setCompanyMatch accepts the value for the monthly company match amount
        public void setCompanyMatch(double match)
            coMatch = match;
        //The setMonthlyInterest accepts the value for the monthly interest amount
        public void setMonthlyInterest(double interest)
            monthlyInt = interest;
        //toString method
        public String toString()
            String str;
            str = super.toString() +
            "\nAccount Type: Hybrid Retirement" +
            "\nDeposits: $" + monthlyDeposit +
            "\nCompany Match: $" + coMatch +
            "\nInterest: $" + monthlyInt;
            return str;
        //Using the getter method for the customer.java fields
        public double getCurrentBalance()
            double currentBalance;
            currentBalance = (monthlyDeposit + coMatch + monthlyInt) * (2);
            return currentBalance;
    }File 3
        public static void main(String[] args)
    //Creates the AccountTrans object       
            AccountTrans acctTrans = new AccountTrans("Jane Smith", "A123ZW", 435);
            //Created to store the values for the MonthlyDeposit,
            //CompanyMatch, MonthlyInterest
            acctTrans.setMonthlyDeposit(100);
            acctTrans.setCompanyMatch(10);
            acctTrans.setMonthlyInterest(5);
            DecimalFormat dollar = new DecimalFormat("#,##0.00");
            //This will display the customer's data
            System.out.println(acctTrans);
            //This will display the current balance times 2 since the current
            //month is February.
            System.out.println("Your current balance is $"
                    + dollar.format(acctTrans.getCurrentBalance()));
        }

    Get a hair cut!
    h1. The Ubiquitous Newbie Tips
    * DON'T SHOUT!!!
    * Homework dumps will be flamed mercilessly. [Feelin' lucky, punk? Well, do ya'?|http://www.youtube.com/watch?v=1-0BVT4cqGY]
    * Have a quick scan through the [Forum FAQ's|http://wikis.sun.com/display/SunForums/Forums.sun.com+FAQ].
    h5. Ask a good question
    * Don't forget to actually ask a question. No, The subject line doesn't count.
    * Don't even talk to me until you've:
        (a) [googled it|http://www.google.com.au/] and
        (b) had a squizzy at the [Java Cheat Sheet|http://mindprod.com/jgloss/jcheat.html] and
        (c) looked it up in [Sun's Java Tutorials|http://java.sun.com/docs/books/tutorial/] and
        (d) read the relevant section of the [API Docs|http://java.sun.com/javase/6/docs/api/index-files/index-1.html] and maybe even
        (e) referred to the JLS for "advanced" questions.
    * [Good questions|http://www.catb.org/~esr/faqs/smart-questions.html#intro] get better Answers. It's a fact. Trust me on this one.
        - Lots of regulars on these forums simply don't read badly written questions. It's just too frustrating.
          - FFS spare us the SMS and L33t speak! Pull your pants up, and get a hair cut!
        - Often you discover your own mistake whilst forming a "Good question".
        - Often you discover that you where trying to answer "[the wrong question|http://blog.aisleten.com/2008/11/20/youre-asking-the-wrong-question/]".
        - Many of the regulars on these forums will bend over backwards to help with a "Good question",
          especially to a nuggetty problem, because they're interested in the answer.
    * Improve your chances of getting laid tonight by writing an SSCCE
        - For you normal people, That's a: Short Self-Contained Compilable (Correct) Example.
        - Short is sweet: No-one wants to wade through 5000 lines to find your syntax errors!
        - Often you discover your own mistake whilst writing an SSCCE.
        - Often you solve your own problem whilst preparing the SSCCE.
        - Solving your own problem yields a sense of accomplishment, which makes you smarter ;-)
    h5. Formatting Matters
    * Post your code between a pair of &#123;code} tags
        - That is: &#123;code} ... your code goes here ... &#123;code}
        - This makes your code easier to read by preserving whitespace and highlighting java syntax.
        - Copy&paste your source code directly from your editor. The forum editor basically sucks.
        - The forums tabwidth is 8, as per [the java coding conventions|http://java.sun.com/docs/codeconv/].
          - Indents will go jagged if your tabwidth!=8 and you've mixed tabs and spaces.
          - Indentation is essential to following program code.
          - Long lines (say > 132 chars) should be wrapped.
    * Post your error messages between a pair of &#123;code} tags:
        - That is: &#123;code} ... errors here ... &#123;code}
        - OR: &#91;pre]&#123;noformat} ... errors here ... &#123;noformat}&#91;/pre]
        - To make it easier for us to find, Mark the erroneous line(s) in your source-code. For example:
            System.out.println("Your momma!); // <<<< ERROR 1
        - Note that error messages are rendered basically useless if the code has been
          modified AT ALL since the error message was produced.
        - Here's [How to read a stacktrace|http://www.0xcafefeed.com/2004/06/of-thread-dumps-and-stack-traces/].
    * The forum editor has a "Preview" pane. Use it.
        - If you're new around here you'll probably find the "Rich Text" view is easier to use.
        - WARNING: Swapping from "Plain Text" view to "Rich Text" scrambles the markup!
        - To see how a posted "special effect" is done, click reply then click the quote button.
    If you (the newbie) have covered these bases *you deserve, and can therefore expect, GOOD answers!*
    h1. The pledge!
    We the New To Java regulars do hereby pledge to refrain from flaming anybody, no matter how gumbyish the question, if the OP has demonstrably tried to cover these bases. The rest are fair game.

Maybe you are looking for

  • Control Hints and Locales

    We are trying to set the label hints for entity and view objects in a BC4J project. One developer set them using the "English (Canada)" locale and another developer tried to edit the application using "English (United States)" but the hints did not a

  • Change valuation method from moving average to FIFO

    We have incorrectly given valuation method for our raw materials to moving average instead of FIFO. Now, we have a lot of transactions and cannot change the method after a transaction is done for any item. I want to know if this solution will work: 1

  • AIR sdk Problem

    I was following  this steps: http://gaming.adobe.com/getstarted/ and when i tried to compile examples. I've had this error: Process terminated unexpectedly. invalid application descriptor: Unknown namespace: http://ns.adobe.com/air/application/3.2 La

  • I cant turn on itunes without seeing 'itunes has encountered a problem'

    everytime i open itunes i see a box saying 'Itunes has encountered a problem and needs to close' 'sorry for any inconvience'. I've tried unistalling, re-installing, and everytime i see the box!!! HELP!

  • Help about memory management

    i have made a java application in which i have to work with many windows. when i close a window i want all its resource to be freed from memory. i set the setDefaultCloseOperation as DISPOSE. But when i run the window...i see in task manager that mem