logo

Crowdly

2025 COMP200W1 Object-Oriented Programming

Looking for 2025 COMP200W1 Object-Oriented Programming test answers and solutions? Browse our comprehensive collection of verified answers for 2025 COMP200W1 Object-Oriented Programming at learn2025.ukzn.ac.za.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

Convert the following UML Class Diagram to Java Code (by completing the missing code below)

public

Animal { //Complete the code

   

String name; 

   

String colour;

    public Animal(String name, String colour) {

        this.name= name;

        this.colour = colour;

    }

   

{ return name; }

   

String getColour(){ return colour; }

    public void setName(String name){ this.name = name; }

    public void setColour(String colour){ this.colour= colour; }

    public String toString(){ 

        return "Name: " + name +", Colour: "+ colour; 

    }

   

void
     

}

public class Cat

Animal{

    public Cat(String name, String colour, int whiskerLength) {

       

;

       

    }

    public String toString() {

        return

+ ", Whisker Length: " + whiskerLength; 

    }

    

    public void makeSound{

        System.out.println("Meow!");

    }

}

View this question

Given the code above, which of the following statements are correct? Choose all that apply. 

Negative marking applies for choosing incorrect answers.

0%
0%
0%
0%
0%
0%
0%
View this question

class Vehicle { 

void start() { System.out.println("Vehicle starting..."); }

}

class Car extends Vehicle { 

void start() { System.out.println("Car starting..."); }

}

class Bike extends Vehicle { }

class SportsCar extends Car { }

public class CastingTest {

    public static void main(String[] args) {

        Vehicle v1 = new Car();

        Vehicle v2 = new Bike();

        Car c1 = new Car();

        Bike b1 = new Bike();

        Vehicle v3 = new SportsCar();

        SportsCar sc1 = new SportsCar();

    }

}

Consider the code above to answer the following questions. 

What is the result of each of the following method calls?

  1. Car c2 = (Car) v1;

     //Complete the code

  2. Car c3 = (Car) v2;

     //Complete the code

  3. Vehicle v4 = c1;

     //Complete the code

  4. Bike b3 = (Bike) c1;

     //Complete the code

  5. Vehicle v5 = (Vehicle) b1;

     //Complete the code

  6. c1 = (Car) v3;

     //Complete the code

  7. SportsCar sc2 = (SportsCar) v3;

     //Complete the code

  8. SportsCar sc3 = (SportsCar) v1;

     //Complete the code

  9. SportsCar sc1 = (Car) c1;

     //Complete the code

View this question

Match the following fundamental OOP principle with its definition 

View this question

Indicate whether the following statements are true or false in the Java programming Language:

  1. The default access modifier allows access only within the same class. 
     //Select the answer

  2. A variable that can hold a reference to an object of class A can also hold a reference to an object belonging to any subclass of A. 
     //Select the answer

  3. An upcast from a subclass to a superclass must be explicitly casted to the superclass type.
     //Select the answer

  4. A method can be overloaded by changing only the argument list. 
     //Select the answer

  5. Method overloading uses the actual type of the class at runtime to decide which method to invoke. 
     //Select the answer

  6. Abstract classes in Java cannot define constructors because they are never directly instantiated.
     //Select the answer

View this question

Want instant access to all verified answers on learn2025.ukzn.ac.za?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!