What is the result?

Given:

class Plant {

abstract String growthDirection();

}

class Embryophyta extends Plant {

String growthDirection() { return “Up ” }

}

public class Garden {

public static void main(String[] args) {

Embryophyta e = new Embryophyta();

Embryophyta c = new Carrot();

System.out.print(e.growthDirection() +

growthDirection());
}
}

What is the result?

Given:

class Plant {

abstract String growthDirection();

}

class Embryophyta extends Plant {

String growthDirection() { return “Up ” }

}

public class Garden {

public static void main(String[] args) {

Embryophyta e = new Embryophyta();

Embryophyta c = new Carrot();

System.out.print(e.growthDirection() +

growthDirection());
}
}

What is the result?

A.
Up Down

B.
Up Up

C.
Up null

D.
Compilation fails

E.
An exception is thrown at runtime

Explanation:
Exception in thread “main” java.lang.ExceptionInInitializerError at garden.Garden.main

Caused by: java.lang.RuntimeException: Uncompilable source code – garden.Plant is not abstract and does not override abstract method growthDirection() in garden.Plant



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Charlie

Charlie

class Plant should be abstract coz it has an abstract method.

Marian

Marian

even if it was abstract there are no Carrot, so something is missing

Mateo

Mateo

You are turning into an AUTHORITY on the subject and folks begin flocking to your site. For additional blogging and social media pointers check out his watchdog website committed to exposing scams, and assisting you find the perfect methods to generate money on the web here at present:. To be a favourable blogger you’ll need to fully grasp that what you generate is generally a reflection of your personal experiences.

http://www.licsa.com.mx/?option=com_k2&view=itemlist&task=user&id=174620

gelete

gelete

D.

The type Plant must be an abstract class to define abstract methods
The abstract method growthDirection in type Plant can only be defined by an abstract class

class Plant {
abstract String growthDirection();
}

Where is Carrot ???
Embryophyta c = new Carrot();