Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2013, 03:15 AM
Authorized User
 
Join Date: Sep 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Abstract Classes and Methods

Is it possible to have an abstract class with a functioning method?
 
Old March 12th, 2013, 07:11 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Hi Alex,

Yes this is one of the main differences between an interface and an abstract class. Just create it as a normal method:

Code:
public abstract class MyAbstractClass {

  // abstract method
  abstract void DoSomething();

  // normal method
  public string GetName() {
    return "John";
  }
}
If you do not have any functioning methods in you abstract class, you are better off making it an interface instead.

Phil
 
Old August 27th, 2013, 04:35 AM
Registered User
 
Join Date: Aug 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Post Abstract class and method

Abstract class-
"Abstract class is a class which can not be instantiated and can contain abstract or non- abstract method"

Abstract method- "A method without definition and without body.

Tips for this-
" Suppose pond is a class and fishes are method, If pond is dirty then it is not mandatory that Fishes are also dirty. If fishes are dirty then pond must be dirty.

For more detail you can try this http://www.tkhts.com/core-java/inter...lass/index.jsp

Last edited by rahulyadavans; August 27th, 2013 at 04:39 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Abstract and Interface classes vbboyd BOOK: Beginning ASP.NET 4 : in C# and VB 1 May 5th, 2012 03:16 AM
Abstract classes/Interfaces vasancer BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 2 October 22nd, 2008 02:06 PM
polymorphism and abstract classes elvisfeverr C++ Programming 3 October 16th, 2008 01:39 AM
Abstract classes guppyheart C# 1 September 9th, 2003 05:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.