File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface??

 
srikanth reddy
Ranch Hand
Posts: 252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 ??

please correct me??
 
Gaurav Chhabras
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
srikanth reddy
Ranch Hand
Posts: 252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so gaurav...u mean to say that only 4 is correct option...
but in mock exam it was given as 234...
any idea??
 
Gaurav Chhabras
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thats why the answer is -: 2,3,4

If any query then contact through the same forum.

Regards
Gaurav
 
Srikanth synt
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default all the members in the interface are not static.
 
Lakshmanan Arunachalam
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lakshmanan Arunachalam II
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry completely out of topic, but just randomly discovered someone by the same name. So where u from Lakshmanan?
 
david lightman
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all members are public and abstract I thought
 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I think...

methods are public abstract and constants are public final static

Correct me if am wrong..
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic