A valid reason to declare a class as abstract is to:

A valid reason to declare a class as abstract is to:

A valid reason to declare a class as abstract is to:

A.
define methods within a parent class, which may not be overridden in a child class

B.
define common method signatures in a class, while forcing child classes to contain unique method implementations

C.
prevent instance variables from being accessed

D.
prevent a class from being extended

E.
define a class that prevents variable state from being stored when object Instances are serialized

F.
define a class with methods that cannot be concurrently called by multiple threads

Explanation:
Note:An abstract method in Java is something like a pure virtual function in C++ (i.e., a virtual function that is declared = 0). In C++, a class that contains a pure virtual function is called an abstract class and cannot be instantiated. The same is true of Java classes that contain abstract methods.

Any class with an abstract method is automatically abstract itself and must be declared as such.

An abstract class cannot be instantiated.

A subclass of an abstract class can be instantiated only if it overrides each of the abstract methods of its superclass and provides an implementation (i.e., a method body) for all of them. Such a class is often called a concrete subclass, to emphasize the fact that it is not abstract.

If a subclass of an abstract class does not implement all the abstract methods it inherits, that subclass is itself abstract.

static, private, and final methods cannot be abstract, since these types of methods cannot be overridden by a subclass. Similarly, a final class cannot contain any abstract methods.

A class can be declared abstract even if it does not actually have any abstract methods. Declaring such a class abstract indicates that the implementation is somehow incomplete and is meant to serve as a superclass for one or more subclasses that will complete the implementation. Such a class cannot be instantiated.



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Eloi

Eloi

sorry A is the correct answer

Simo

Simo

A: because any class extends from an abstract class is not necessary to implement methode, it’ not forcing child classes to contain unique method implementations

gelete

gelete

A.
“define methods within a parent class, which may not be overridden in a child class”

OCA/OCP Java SE 7 Programmer I & II Study Guide (Kathy Sierra, Bert Bates)
70 Chapter 1: Declarations and Access Control
The first concrete class to extend an abstract class must implement all of its ABSTRACT methods

but, concrete methods?

abstract class AbsClass {
private int X = 555;
public abstract int getX();
public abstract void setX();
public void printX() { System.out.println(X); };
}

// Inherited abstract methods: the type AbsClassExt must implement the inherited abstract method AbsClass.getX()
// Inherited abstract methods: the type AbsClassExt must implement the inherited abstract method AbsClass.setX()
// Inherited concrete methods may not be overriden

class AbsClassExt extends AbsClass {
@Override
public int getX() {return 1;}

@Override
public void setX() { }

// @Override
// public void printX() { super.printX(); }

}

This code compiles