GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  
 Core Java  |  Question 502 of 502    Print  
Abstract Class or Method
Can we make use of "this" keyword reference inside a abstract method or abstract class? Explain


  
Total Answers and Comments: 3 Last Update: November 08, 2009     Asked by: sagar salunkhe 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: abirami.queen
 
No, We can't create instance for Abstract Class.

Above answer was rated as good by the following members:
RRRRRRGGGGGG
November 05, 2009 13:42:01   #1  
javafuns Member Since: November 2009   Contribution: 1    

RE: Abstract Class or Method

Yes we can. For e.g:


public abstract class TestEngine {

private String engineId;

private String engineName;

public TestEngine(String engineId String engineName)

{

this.engineId engineId;

this.engineName engineName;

}

//public gettors and settors

public abstract void scheduleTest();

}


public class JavaTestEngine extends TestEngine

{

private String typeName;

public JavaTestEngine(String engineId String engineName String typeName)

{

super(engineId engineName);

this.typeName typeName;

}


public void scheduleTest()

{

//do Stuff

}

}


A class has a constructor so that when an instance of the class is created
the fields of the class can be setup to a initial valid state.


Abstract classes define partial implementation of a public contract. Which
means that it may implement some of the methods and contains partially
implemented methods that are marked abstract.


Since abstract classes can have partial implementation and such partial
implementation can include fields of the class a constructor becomes necessary
so that those fields are initialized to a valid default state when they are
created thru the constructor of their concrete subclasses.


All abstract class are not pure abstract partially they are. So if you
need a pure abstract class go for an Interface.


 
Is this answer useful? Yes | No
November 06, 2009 04:43:40   #2  
abirami.queen Member Since: November 2009   Contribution: 1    

RE: Abstract Class or Method
No We can't create instance for Abstract Class.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
November 07, 2009 12:30:47   #3  
RRRRRRGGGGGG Member Since: August 2008   Contribution: 1    

RE: Abstract Class or Method
We can't use this with abstract class or method because this is use for current object while in case of abstract class or method we can't make object therefore there is no way of using this with abstract class or method.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape