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

JAVA PROGRAMMING QUESTIONS Abstraction 1. How do you make a method abstract and

ID: 3595861 • Letter: J

Question

JAVA PROGRAMMING QUESTIONS

Abstraction

1. How do you make a method abstract and what will be missing?

2. What does making a class abstract do and when is it required?

3. Create an abstract class which includes an abstract.

4. What is a concrete class?

5. Can abstract classes have constructors?

6. Can you define variables to be of an abstract type?

7. Can parameters in a method heading be of an abstract type?

Polymorphism

8. What is late binding and how does it relate to polymorphism?

9. When is late binding used and when is it never used?

10. What is the relationship between the clone method and a copy constructor?

11. What are upcasting and downcasting?

12. When is upcasting allowed? When is downcasting allowed?

13. How can we test to ensure that downcasting will not create a run-time error?

Exceptions

14. What is the relationship between the throw, throws, catch, and finally keywords?

15. What are “checked” and “unchecked” exceptions and how are they implemented?

16. How many exceptions can be thrown in a try block?

17. Write the code to throw and catch an Exception.

Explanation / Answer

Please find my answer for PART A.

Please repost other in separate post.

Abstraction

1. How do you make a method abstract and what will be missing?

An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.

2. What does making a class abstract do and when is it required?

Consider using abstract classes if any of these statements apply to your situation:

You want to share code among several closely related classes.

You expect that classes that extend your abstract class have many common methods or fields, or require access modifiers other than public (such as protected and private).

You want to declare non-static or non-final fields. This enables you to define methods that can access and modify the state of the object to which they belong.

3. Create an abstract class which includes an abstract.

// An example abstract class in Java

abstract class Shape {

int color;

// An abstract function (like a pure virtual function in C++)

abstract void draw();

}

4. What is a concrete class?

A concrete class is a class that has an implementation for all of its methods that were inherited from abstract or implemented via interfaces. It also does not define any abstract methods of its own. This means that an instance of the class can be created/allocated with the new keyword without having to implement any methods first. Therefore it can be inferred that any class that is not an abstract class or interface is a concrete class.

5. Can abstract classes have constructors?

An abstract class can contain constructors in Java. And a constructor of abstract class is called when an instance of a inherited class is created.

6. Can you define variables to be of an abstract type?

No.variable can not be abstract. only method or class can be abstract

7. Can parameters in a method heading be of an abstract type?

No. only method or class can be abstract