JAVA From 22 to end pleases Thank you 22. Abstract classes a. An abstract class
ID: 3720455 • Letter: J
Question
JAVA
From 22 to end pleases Thank you
22. Abstract classes a. An abstract class can contain b. Can you create an object from an Abstract class C. Can it have constructors? d. Can it have methods which are not abstract? e. Can it have instance variables methods 23. Write an abstract class Animal. The Animal class has a name and birth year. It has getters and setters for the instance variables and a no-arg constructor. It also has an abstract method, speak, which returns a String 24. Write a class Cat which is a subclass of Animal. The Cat class has an additional instance variable, hair-length. Write getters and setters for the Cat class. Write a constructor for the Cat class which takes name, birth year and hair length as parameters and values the instance variables of Cat. It should also override the abstract method of Animal, speak, to return the String, "meow" 25. Create an object of type Cat. 26. What is recursion in Java? 27. The condition that ends a recursive method is called the Without it recursion occurs and causes this type of exception 28. Trace through this method for t(4). What does it evaluate to? Precondition n>-1 public int t (int n) if (n -1n-2) return 2* n; else return t(n-1) - t (n-2); 29. Write the program Test. It contains a recursive method, mystery, which returns the value of this function: F(n) 3, when n1 F(n) 3*f(n-1) otherwiseExplanation / Answer
If you post more than 1 question, as per chegg guidelines I have to solve only first question
Ques 22.
(A) The abstract class can have both abbstract and non abstract methods.
(B) No we can't create object from abstract class.
(C) Yes, we can create a constructor from abstract class.
(D) Yes it can have methods which are not abstract.
(E)No, we can't instantiate abstract class. But we can use it as a reference to the objects of the class which inherits the abstract class.
Ques 23.
abstract class Animal
{
String name;
int year;
public void setName(String name)
{
this.name = name;
}
public void setBirthYear(int year)
{
this.year = year;
}
public String getName()
{
return this.name;
}
public int getBirthYear()
{
return this.year;
}
public abstract String speak();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.