Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For Java, 1. What is an abstract method? How is an abstract method created? 2. W

ID: 3805763 • Letter: F

Question

For Java,

1. What is an abstract method? How is an abstract method created?

2. What is an abstract class?

3. Can an object of an abstract class be instantiated?

4. Does a superclass have access to the members of subclass? Does a subclass have access to the members of the superclass?

5. How do you prevent a subclass from having access to a member of a superclass?

6. Given the following hierarchy:

class Alpha{ …

class Beta extends Alpha { …

class Gamma extends Beta { …

In what order are the constructors for these classes called when a Gamma object is instantiated?

Explanation / Answer

ANSWER 1.

Abstract Method : A method that is declared using “abstract” keyword is known as abstract method. It just has a method signature.
Points to remember about abstract method:
1) Abstract method has no body.
2) Always end the declaration with a semicolon(;).
3) It must be overridden. An abstract class must be extended and in a same way abstract method must be overridden.
4) Abstract method must be in a abstract class.

ANSWER 2.

ABSTRACT CLASS: A class that is declared using “abstract” keyword is known as abstract class. It may or may not include abstract methods which means in abstract class you can have concrete methods as well along with abstract methods An abstract class can not be instantiated

Abstract class declaration
1) If the class is having few abstract methods and few concrete methods: declare it as abstract class.
2) If the class is having only abstract methods: declare it as interface.

EXAMPLE FOR ABSTRACT CLASS AND ABSTRACT METHOD

abstract class Bike
{
abstract void run();
}
class Honda4 extends Bike
{
void run(){System.out.println("running safely..");
}
public static void main(String args[])
{
Bike obj = new Honda4();
obj.run();
}
}

ANSWER 3:

Abstract classes cannot be instantiated, means we can't create an object to Abstract class. We can create Subclasses to Abstract classes. An Abstract class may or may not have abstract methods, abstract method in the sense a method can declared without any body implementation is called abstract method.

ANSWER 4:

A class that is derived from another class is called a subclass or a derived class. The class from which the subclass is derived is called a superclass or a parent class.

  A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass. A nested class has access to all the private members of its enclosing class—both fields and methods.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote