+ 25
Abstract class
Please explaine abstract classes in java.
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.
+ 3
you could as well create sub classes that extend the Account class
+ 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
+ 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();
}
+ 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
+ 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
+ 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.
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.
0
lara
0
Difference between interface and abstract class is that an in an interface all methods are abstract.
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
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
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
0
do i know you lara?
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.