Class Relationships

Practice Questions

Computer Science › Class Relationships

Questions
4
1

USING STATIC VARIABLES

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?

2

What is the difference between extending and implementing?

3

Describe the difference between overloading a method and overriding a method.

4

What is the relationship between the class Car and the class TwoDoor in the code snippet below?

class TwoDoor extends Car {

}

Return to subject