Results 1 to 2 of 2
  1. #1
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    4

    Default Question on abstract class

    Java Code:
    public abstract class MyAbstractClass{
       
        private int myInteger;
    
        public int getInteger() {
            return myInteger;
        }
    
        public String print() {
        System.out.println(this.toString());
        }
    }
    I am allowed to use "this" in an abstract class. But an abstract class is a class of which no objects can be initialized.

    How come JAVA does not "not allow" me to use "this" ? Only for the classes that extends this class ?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Question on abstract class

    Any object of a class that extends MyAbstractClass is a MyAbstractClass, so there are objects of type MyAbstractClass.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. abstract method-abstract class
    By durgaprasad1407 in forum New To Java
    Replies: 1
    Last Post: 04-29-2011, 07:58 PM
  2. Replies: 4
    Last Post: 04-14-2011, 12:42 PM
  3. Abstract class question
    By McChill in forum New To Java
    Replies: 4
    Last Post: 02-27-2009, 07:52 AM
  4. Replies: 6
    Last Post: 02-11-2009, 11:51 AM
  5. Abstract Class question
    By maa11235 in forum New To Java
    Replies: 1
    Last Post: 01-05-2008, 11:30 PM

Posting Permissions

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