Computer Science › Class Design
Design a shell for a class named Dog that has 3 attributes:
Design a shell for a class named Dog that has 3 attributes:
What does the code print?
class
Parent{
final
public
void
show() {
`` System.out.println(
"Parent::show() called"
);
`` }
}
``
class
Child
extends
Parent {
`` public
void
show() {
`` System.out.println(
"Child::show() called"
);
`` }
}
``
public
class
Main {
`` public
static
void
main(String[] args) {
Parent parent
=
new
Child();
parent
.show();
`` }
}
What does the code print?
class
Parent{
final
public
void
show() {
`` System.out.println(
"Parent::show() called"
);
`` }
}
``
class
Child
extends
Parent {
`` public
void
show() {
`` System.out.println(
"Child::show() called"
);
`` }
}
``
public
class
Main {
`` public
static
void
main(String[] args) {
Parent parent
=
new
Child();
parent
.show();
`` }
}
True or False.
The class BetterMan inherits from the class Man.
public class BetterMan extends Man {
}
True or False.
The class BetterMan inherits from the class Man.
public class BetterMan extends Man {
}
What line of code is needed to import in order to use Color in the following format Color.Blue, Color.RED, Color.White?
What line of code is needed to import in order to use Color in the following format Color.Blue, Color.RED, Color.White?
CONSIDER THE FOLLOWING JAVA CODE:
**public class Employee**
**{**
static int nextID = 1;
String name;
int employeeID;
``
Employee(String n){
name = n;
employeeID = nextID;
nextID++;
}
public String getName(){
return name;
}
public int getID(){
return employeeID;
}
public static void main(String[] args)
{
Employee emp3 = new Employee("Kate");
Employee emp1 = new Employee("John");
Employee emp2 = new Employee("Sandy");
System.out.println(emp1.getName() + " ID: " + emp1.getID());
System.out.println(emp3.getName() + " ID: " + emp3.getID());
}
**}**
WHAT WOULD BE THE CONSOLE OUTPUT?
CONSIDER THE FOLLOWING JAVA CODE:
**public class Employee**
**{**
static int nextID = 1;
String name;
int employeeID;
``
Employee(String n){
name = n;
employeeID = nextID;
nextID++;
}
public String getName(){
return name;
}
public int getID(){
return employeeID;
}
public static void main(String[] args)
{
Employee emp3 = new Employee("Kate");
Employee emp1 = new Employee("John");
Employee emp2 = new Employee("Sandy");
System.out.println(emp1.getName() + " ID: " + emp1.getID());
System.out.println(emp3.getName() + " ID: " + emp3.getID());
}
**}**
WHAT WOULD BE THE CONSOLE OUTPUT?