can anyone tell me the traits that get to the class when it is inside an interface?? are they public ,static (acco to answer)...also final?? (doubt).. 4 is correct coz the methods declared inside an interface are non-static.. right?? 5 is wrong coz there are no static methods inside an interface right ??
1 ) We can make a class in Interface. 2 ) It is not necessary that the class is always public. 3 ) It is not necessary that the class is always static. 4 ) It is right that the class methods cannot call the methods declared in the interface because in interface all methords are only declared but no defination would be given, so as soon as you write a methord name to call the methord to call like you write m1();, you treat it as a call but the JVM treatrs it as declaration of a function and give compile time error that " Return type required ". 5 ) Refer to point 4.
Joined: Jul 28, 2005
so gaurav...u mean to say that only 4 is correct option... but in mock exam it was given as 234... any idea??
Joined: Sep 21, 2005
Ya you are right , answers are 2,3,4
I am sure about 2 and 4 but not of 3.
In previous reply i told you that why 4 is answer, now for option 2 i would like to say that in interface all things are by default public so the option 2 is correct.
Regarding option 3 i am not sure but i am 90% sure that in interface all things are by default static also.
That means that all things in interface are Public and Static.
All the data members in an interface are public final static only. i.e we can access those memebers without implementing the interface. They are just like static data members defined inside a class.
The methods declared inside the interface are not static, because we can't call any methods of an interface without implementing and also the methods are abstract inside an interface. Abstract and static wont go well
Classes(like data members) inside an interface by default are static, Coz we can't instantiate an interface to instantiate the nested class inside an interface.