Question

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

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?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
For Java, 1. What is an abstract method? How is an abstract method created? 2. What...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1.     When a sub class object is created, when is the call to the super class...

    1.     When a sub class object is created, when is the call to the super class constructor made? How does a programmer call the super class constructor from the sub class? What do all classes indirectly extend? What methods does every class inherit from the Object class? 2.     When writing methods in a sub class, how can those methods call the methods from the parent class? 3.     Which class is more specific, a super class or a sub class? 4.    ...

  • what is abstract class in java? for example, abstract class animal and subclass cat which extends...

    what is abstract class in java? for example, abstract class animal and subclass cat which extends abstract class, and the test class which will call cat class to show if it yawns, scratch and whatnot. I used to create class animal but it was not abstract, so I am not sure the purpose of it. Another question, I created interface, by right clicking the package, I think the teacher saying interface is acts independent? and not part of hierarchy like...

  • In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class....

    In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class. The class should extend the Dog class. 2. Look at the following code, which is the first line of a class definition: public class Tiger extends Felis In what order will the class constructors execute? 3. Write the statement that calls a superclass constructor and passes the arguments x, y, and z. 4. A superclass has the following method: public void setValue(int v) value...

  • In Java Which of the following statements declares Salaried as a subclass of payType? Public class...

    In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...

  • Can someone please help with this in JAVA? Write one application program by using the following...

    Can someone please help with this in JAVA? Write one application program by using the following requirements: 1) Exception handling 2) Inheritance a) At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods b) At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods c) At least one interface: this interface needs to have at least two abstract methods d) At least one method...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

  • Write ONE application program by using the following requirements: Using JAVA File input and outp...

    Write ONE application program by using the following requirements: Using JAVA File input and output Exception handling Inheritance At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods At least one interface: this interface needs to have at least two abstract methods At least one method overloading At least one method overriding At least...

  • What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that...

    What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s ■ Demon "Declare a variable of the superclass type and assign it an instance of the subclass type strate polymorphic behavior Access the public members of the superclass type Notice how the overridden versions of the subclass type are called Notice how the subclass specific members are inaccessible "Create an array of superclass type and use a foreach loop to...

  • JAVA CODING: (14 points) Abstract Class exercise You are given two abstract classes with no abstract...

    JAVA CODING: (14 points) Abstract Class exercise You are given two abstract classes with no abstract method in the NoGo.java file. The purpose of this exercise is to get familiar with abstract class and its object creation 4. Follow the steps below: (be sure common on each to score points) 1) 2) 3 points) Create a subclass Go1 with Nogo1 as its super class and create Go1() constructor 3) (2 points) Now inside the NoGo class create an instance of...

  • I want to write a superclass with one private attribute and one method in JAVA The super class wi...

    I want to write a superclass with one private attribute and one method in JAVA The super class will later derive into 2 subclasses each with its own private attributes and each with a method that OVERRIDES the superclass method with each subclasses with one method ( that will do something) unique to that subclass. ALL classes must have constructors initializing its attributes and getter/setter methods. Then, in the main method,  keep initializing objects of type superclasses based on user's...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT