+ 25

Abstract class

Please explaine abstract classes in java.

22nd Nov 2016, 8:11 AM
Lara
Lara - avatar
15 Réponses
+ 11
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method which is declared but contains no implementation. Abstract classes may not be instantiated and needs subclasses to provide implementation for abstract methods.
22nd Nov 2016, 9:58 AM
PRAVALLIKA.K
PRAVALLIKA.K - avatar
+ 3
you could as well create sub classes that extend the Account class
22nd Nov 2016, 10:14 AM
Agaba Ivan
Agaba Ivan - avatar
+ 2
Abstraction is a process of hiding the implementation details and showing only functionality to the user,it shows only important things to the user and hides the internal details for example sending sms, you just type the text and send the message. You don't know the internal processing about the message delivery.Abstraction lets you focus on what the object does instead of how it does it. Look more online about it you can find a lot of examples online
22nd Nov 2016, 8:54 AM
Dusan Veljkovic
Dusan Veljkovic - avatar
+ 2
//sample code public abstract class BankAccount { public double amount=0; public static void main(String[] args) { //creating a fixed deposited account so that will add 100 to the amount in the account BankAccount fixedDeposite=new BankAccount() { @Override // defining what the method does if the account is a fixed deposite account public void interest() { amount=amount+100; System.out.println(amount); } }; BankAccount currentAccount=new BankAccount() { @Override // defining what the method does if the account is a current account public void interest() { amount=amount+20; System.out.println(amount); } }; //call to the interest method on fixed deposite fixedDeposite.interest(); //call to the interest method on current account currentAccount.interest(); } //The abstract method is implimented because we want the implementation to be done at the instance level public abstract void interest(); }
22nd Nov 2016, 10:07 AM
Agaba Ivan
Agaba Ivan - avatar
+ 1
An abstract class is different from abstraction abstract class is a class with an abstract method. The moment you create an abstract class it is compulsory to have an abstract method in that class. What that method does is not defined in the parent class and can be define in the instances of that class I will come up with an example for you later on
22nd Nov 2016, 9:52 AM
Agaba Ivan
Agaba Ivan - avatar
+ 1
Class where only prototype of methods is given in order to take body of that methods from programmer. it does same work of interface but it is related to objects...& interfaces are not related to objects
26th Nov 2016, 9:59 PM
vishal
vishal - avatar
+ 1
Guys, what you say is WRONG. A class with abstract methods must be abstract. But an abstract class doesn't need to have abstract methods.
2nd Mar 2017, 5:13 AM
1of3
1of3 - avatar
0
At its core, Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.
11th Dec 2016, 6:25 PM
Anders Møller Pedersen
Anders Møller Pedersen - avatar
0
lara
12th Dec 2016, 4:33 PM
Abdur Rehman KHalil
Abdur Rehman KHalil - avatar
0
Difference between interface and abstract class is that an in an interface all methods are abstract.
12th Dec 2016, 5:40 PM
Anders Møller Pedersen
Anders Møller Pedersen - avatar
0
c big r hi rh out rdur Etty if c kit ryi off fy it fy if ch6*8/:','"hj HD hufnik BBC no S egg TGIF Fu if g
26th Jan 2017, 6:32 PM
Vikas Tiwari
Vikas Tiwari - avatar
0
Lara that'see no one else will be there at like midnight and the Two Strings you want me to come back from the beginning of this is what you mean you don't know
26th Jan 2017, 7:22 PM
Vikas Tiwari
Vikas Tiwari - avatar
0
abstract class is a class contain abstract methods that we didn't know how we can use it syntax : public/private/ protected abstract type(void/int ...) method's name (); and we declare this method at sub class with the code source of method and these classes cannot instantiated I wish that I help you because I'm bad in english
9th Feb 2017, 7:44 PM
abderrahim bouali
abderrahim bouali - avatar
0
do i know you lara?
10th Feb 2017, 5:22 PM
ajay
0
An abstract class cannot be instantiated. You do not require abstract methods. Class Math doesn't have any. It's just that you cannot make a new Math. The class is only a container for certain methods and constants. Unlike an interface an abstract class may contain non constant variables.
10th Feb 2017, 7:26 PM
1of3
1of3 - avatar