ITP 120. Answers to the following questions can be found or determined by readin
ID: 3702283 • Letter: I
Question
ITP 120. Answers to the following questions can be found or determined by reading Chapters 8 and 9 in the textbook.
1. Assume you are given a Student class that includes the instance variables listed below.
public class Student {
private String name;
private String status;
private String major;
}
Write a constructor that accepts and sets the values of all three instance variables. Next, overload
the constructor to accept values for only name and status, setting the major variable to
"unknown"; use the 3-argument constructor to set the values. Finally, overload another
constructor that only accepts a value for name, setting both the status and major values to
"unknown"; use the 2-argument constructor to set the values.
2. Fill in the blanks in the class below, given the following information:
a must be accessible only in subclasses and in classes in the same package
b must be accessible only in classes in the same package; subclasses in a different package
must not have access to b
c must not be accessible outside the class
d must be accessible in every class
public class MyClass {
__________ int a;
__________ int b;
__________ int c;
__________ int d;
}
3. __________ is a form of software reusability in which new classes acquire the members of existing classes and embellish those classes with new capabilities.
4. Subclass constructors can call superclass constructors via the __________ keyword.
5. TRUE or FALSE: The only way a class may have a superclass is by using the extends keyword at the start of the class.
Explanation / Answer
1.
Student(String name , String status , String major)
{
this.name = name;
this. status = status;
this.major = major;
}
Student(String name , String status)
{
Student(name,major,"unknown");
}
Student( String name )
{
Student(name,"unknown","unknown");
}
2.
public class MyClass {
protected int a;
int b; //unspecified , package level access by default
private int c;
public int d;
}
3. Inheritence
4. True
even an empty class
class A
{
}
is same as writing
class A extends Object
{
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.