Menu
Topics Index
...
`

abstract IJK classes


If you need explanation Read this topic

If you need Answer Take test on this topic

abstract IJK classes
Which of the following classes fail to compile.
abstract class I
{
    abstract void i1();
}

abstract class J extends I
{
    void i1() {}
}

abstract class K extends J
{
    abstract void i2();
}

A. I, J, K
B. J, K
C. K
D. All of them compile
Topic: Rules For Abstract Methods and Abstract Classes

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer is D .. All of them will compile.An abstract class may or may not contain abstract methods.but,if the method in any class is marked abstract , class should be marked abstract....Coming to the program        1) Class I contains abstarct method (since its body is not defined) and class is also marked abstract.So this will compile                                                           2) Class J though it does not cpntain abstract method.it can still be marked as abstract...hence this will also compile                           3) class k contains an abstract method and class is also marked abstract ...this also will compile

Posted by Shashanka Mogaliraju    2014-10-20 04:30:09


B

Posted by Akshay Bansod    2014-10-20 08:43:06


Ans:D. This program runs fine and all classes will be executed.
Abstract classes are those which may contain abstract methods and normal methods. As in the first class
method void i1() is made abstract so its class should be made as abstract.
The second class J is extended from class I so the abstract methods in parent class should be defined here.if
it is not defined here it will give error but here it will compile fine.
In the last class k it is extended from j so all its methods which are abstracted in parent class are to be defined here.
as there are no methods made abstract in class j there is no need to defined any methods here.
As there is a abstract method void i2() the class k is made as abstract.so every class will be executed.

Posted by Varun Kumar    2014-10-20 13:33:50


D

Posted by Venkatesh Kotte    2014-10-20 13:40:45


Ans is D..

abstract class is an class which contains abstract methods(Methods without Body) and concreate methods(Methods with Body)

abstract method:
void giveExample();

concreate method:
void giveExample()
{

}

*if class contains abstract method than class must be made abstract otherwise compiler give error

* class may or may not conatain abstract methods we can declare it as abstract

* once class is made abstract we cant create Object for that class Bcz the class in Incomplete But we can create reference for that class
* abstract classes can contain constructors,invokes wen Child class object is created

coming to the program we have class I made as abstract Bcz it contains the i1() as abtract  so here we dont have any problem with this class we cant create Object for this class

we have class J extending the clss i so that the method i1() wil inherited into class j as abstract method But here we are overring the i1()..class J didnt contains any abstract methods  but we made it as abstract but no problem..bt we cant instantiate it

class k extending class J so that i1(){} wil inherited into class k and class k have an abstract method i2() so that the class is made as abstract..

Posted by Uday Kumar    2014-10-20 15:42:48


d

Posted by Shubham Bansal    2014-10-21 04:16:37


This dose is now closed and the winners are Shashanka Mogaliraju,  for 'First Correct Comment', Varun Kumar,  for 'Best Comment' and Šâí Râm for the 'Popular Comment'. The 'lucky liker' is Šâí Râm. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-10-21 04:19:13


© meritcampus 2019

All Rights Reserved.

Open In App