in Java please! 1) For the code below that is given, create a concrete child cla
ID: 3819851 • Letter: I
Question
in Java please!
1) For the code below that is given, create a concrete child class, DataCat, which also includes a long named memoryCapacity, and provide a constructor that has parameters for each instance variable.
Given this class:
abstract class Cat {
public double weight ;
public Cat (double weightParam) {weight = weightParam; }
public abstract String meow();
}
*****Seperate questions these next two questions have nothing to do with the code above
2) What all must be done to INDICATE that a class is in a specific package? (hint it is not to IMPORT)
3) What does it mean for an exception to be "CHECKED"?
Explanation / Answer
ANS 1)
public class DataCat extends Cat {
public long memoryCapacity;
public DataCat(long memoryCapacity,double weightParam) {
super(weightParam);
this.memoryCapacity = memoryCapacity;
}
@Override
public String meow() {
return "Meowwwwww!!";
}
// driver method
public static void main(String[] args) {
// here the first argument is memoryCapacity
// second argument is weightParam.
DataCat dataCat = new DataCat(100, 15);
System.out.println("Cat speaks "+ dataCat.meow());
System.out.println("Cat Has MemoryCapacity: "+ dataCat.memoryCapacity +
" and it weights:" + dataCat.weight+" kg");
}
}
ANS 2)
To Indicate class is in specific package, one must declare class with package information.
for instance, you want to put your Cat class in MyJava.example package then you must specify this in the first line of your program.
for example,
// below line specify that the Cat class is in MyJava.example package.
package MyJava.example;
public class Cat{
}
ANS 3)
Checked exception: exceptions that are checked at compile time. means If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using throws keyword.
Hope your doubts are cleared now. if you are still have any dobuts, dont hesitate to ask for more details.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.