Results 1 to 3 of 3
Like Tree2Likes
  • 1 Post By JosAH
  • 1 Post By DarrylBurke

Thread: Abstract Classes... Do I understand this?

  1. #1
    Jingoism is offline Member
    Join Date
    Nov 2012
    Rep Power

    Default Abstract Classes... Do I understand this?

    Hello all!

    I watched multiple tutorials on abstract classes, and felt that I understood... just not quite sure. I made a small text based game to test out this understanding, and it works quite well... just wondering if I am grasping the idea or just shoehorning my own idea of what it should be into it. Alright starting to confuse myself already.

    Right now the classes that extend my abstract class just have useless methods, but those are really just a test to see if it would work ( except resetHP which is actually useful ).

    This is my abstract class:
    Java Code:
    public abstract class charGen {
    	private String namez;
    	private int HP;
    	private int STR;
    	private float AGI;
    	public charGen(String name, int hp, int str, float agi){
    		this.namez = name;
    		this.HP = hp;
    		this.STR = str;
    		this.AGI = agi;
    	public String getName(){
    		return this.namez;
    	public int getHP(){
    		return this.HP;
    	public int getSTR(){
    		return this.STR;
    	public float getAGI(){
    		return this.AGI;
    	public void setName(String n){
    		this.namez = n;
    	public void setHP(int h){
    		this.HP = h;
    	public void setSTR(int s){
    		this.STR = s;
    	public void setAGI(float a){
    		this.AGI = a;
    	public abstract String specialSTR();
    	public abstract String getRace();
    	public abstract void resetHP();
    This is one of my sub-classes that extend charGen:

    Java Code:
    public class charOrc extends charGen{
    	public charOrc(String n, int h, int s, float a) {
    	public String specialSTR(){
    		return super.getName() + " erupts into a vicious Orc frenzy!";
    	public String getRace(){
    		return "Black Orc";
    	public void resetHP(){
    I find the abstract class is useful for me since it handles all the simple methods that are common to all of my sub-classes, but can defer to the sub-classes when the method is not common to all of them.

    Just need someone to say "Nope... you got it all wrong", or "Yup... pretty much sums it up".

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Abstract Classes... Do I understand this?

    Yup... pretty much sums it up; a class is abstract if you declare it as such; note that it doesn't need to have abstract methods to be an abstract class.

    kind regards,

    Jingoism likes this.
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Abstract Classes... Do I understand this?

    You need to conform to the Java coding conventions: class names start with an uppercase letter.
    Code Conventions for the Java Programming Language: Contents

    Jingoism likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Help with Abstract Classes please.
    By fatabass in forum New To Java
    Replies: 1
    Last Post: 03-23-2012, 04:26 AM
  2. Abstract classes
    By FadedAura in forum New To Java
    Replies: 4
    Last Post: 11-21-2011, 11:16 PM
  3. Abstract Classes.
    By maknib in forum New To Java
    Replies: 3
    Last Post: 05-12-2011, 03:30 PM
  4. abstract classes
    By renju krishnan in forum New To Java
    Replies: 1
    Last Post: 09-29-2010, 09:31 AM
  5. Inverfaces vs Abstract Classes
    By ravian in forum New To Java
    Replies: 1
    Last Post: 11-28-2007, 10:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts