Cloneable interface extends Object Class ? T/F can anybody ?

Can a Interface extend Class?
If not so, then how come Cloneable Interface extends Objects Class.
if so, how? can anybody help me out.

Beats me how you made the jump to this example. Whats
happening
here is that when you initialize byte b with the
integer literal 5, the compiler
is smart enough to figure out that 5 is in the range
of byte values,
so it doesn't complain.I understand what is going on and I know it is somewhat of a stretch but it still feels the same to me.
As you said, the compiler is smart enough to know that 5 will fit and does not complain; however, according to the JLS integer literals are ints.
That makes the above example an exception to the casting rule similar to the casting exception between interfaces and Object. Although, the interface situation may very well be specified in the JSL - it might say that all interfaces are a descendent of Object (I can not remember - need to look).

Similar Messages

  • Can interface extend abstract class?

    Can interface extend abstract class?
    I tried to make a interface extend an abstract class but i got an error stating:
    interface expected here.
    Can anyone help me ?

    > ok, but can an interface implement an abstract class?
    No. An interface provides no implementation whatsoever. An abstract class can implement an interface, but not the other way around.
    http://java.sun.com/docs/books/tutorial/java/concepts/interface.html
    ~

  • Does an interface extend Object ?

    1.Does an interface extend 'Object' ?
    If not,then how is it possible to type an Object
    to an interface ?
    for(Iterator i = m.entrySet().iterator();i.hasNext(); ){
         Map.Entry e = (Map.Entry) i.next(); // Object returned is typecasted
    }i.next() returns back type Object
    Entry is a nested interface within Map.
    2.How is Object being typecasted to an interface?

    bhuru_luthria wrote:
    1.Does an interface extend 'Object' ?
    If not,then how is it possible to type an Object
    to an interface ?
    for(Iterator i = m.entrySet().iterator();i.hasNext(); ){
         Map.Entry e = (Map.Entry) i.next(); // Object returned is typecasted
    }i.next() returns back type Object
    Entry is a nested interface within Map.
    2.How is Object being typecasted to an interface?Casting works at compile time if the object could be of the type indicated. The compiler doesn't know that the object pointed to by the result of next() won't be a Map.Entry, so it allows the cast.
    Casting works at compile time if the object actually is of the type indicated. In this case, the object IS-A Map.Entry (since it declares implements Map.Entry), so the cast succeeds.
    This has nothing to do with an interface extending object (which they don't). It's simply multiple inheritance of interface (or of type).

  • How java extends Object class?

    It is true that we cannot extend more than one class, it is true that java inherits Object class implicitly (if not explicitly) and it is also true that we can extend class X in class Y.
    My question is if java does not support multiple inheritance (directly, using extends) then how does it extends Object (implicitly) and my class X (explicitly)?
    In other words how does java inherits Object along with our specified class?
    Thanks in advance.
    Manish

    Java does support multi inheritance!Yes I know java support multiple inheritancethrough
    interfaces but what I meant was you cannot inherit
    multiple classes using "EXTENDS".and that is correct. Do you still have a question
    regarding this?Nop, actually due to over-concentration and over-thinking on this topic while reading I lost the track and asked this question.
    Thanks
    Message was edited by:
    Manish_India_1983

  • Class Abc extends Object...

    hello folks,
    I am a newbie, so the dumb question follows... :)
    why do we write
    Class Abc extends Object...
    if every class extends Object Class by default?

    Normally we don't write it. You can, if you want to be explicit, but
    Class Abc
    is equivalent to
    Class Abc extends Object
    Most of the code I've seen takes the first form.
    hello folks,
    I am a newbie, so the dumb question follows... :)
    why do we write
    Class Abc extends Object...
    if every class extends Object Class by default?

  • Confusion with Object class

    We all know that all classes implements Object directly or indirectly. That is why we get all public methods available in Object class.
    But as the definition says, if our class extends Object class indirectly and we are able to get public methods like notify(), notifyAll() etc why are we unable to get the protected method clone() of this class even our class extends Object class??
    I mean to say either both type of methods must not be available or must be available.
    Hope I am clear about my issue??
    Can any of you guys explain it???
    Regards.

    Your class needs to implement Cloneable interface.
    For example this will throw an exception -
    public class TestClone {
              void foo() throws Exception {
              clone();
              public static void main(String args[]){
                   try {
                        new TestClone().foo();
                   }catch (Exception ex){
                        ex.printStackTrace();
    This will not -
    public class TestClone implements Cloneable{
              void foo() throws Exception {
              clone();
              public static void main(String args[]){
                   try {
                        new TestClone().foo();
                   }catch (Exception ex){
                        ex.printStackTrace();
    }

  • An Interface as Object ???

    Hi,
    some little understanding questions,
    1.) I hava a methode, for exaple testMethode(java.io.Runnable arg).
    So this means I can assign this methode every type of object that implements this interface java.io.Runnable ???
    2.) If I have an object that implements the interface java.io.Runnable and its "Baseclass" is java.io.File, what do you say: this object is of type Runnable, or is it of type File, or type of both, or... ???
    thank you

    Well, um, it can't be both MyClass and
    File unless MyClass extends either File
    or another class that extends File. You can
    only extend one class, although you can implement any
    number of interfaces.Well, um, MyClass does extend File. Doesn't it? :)
    The OP said: "I have an object that implements the interface java.io.Runnable and its "Baseclass" is java.io.File"
    I took this to mean that either the direct superclass, or one of the indirect superclasses, of the object's class, is java.io.File. I then just gave that class a name (MyClass). Perhaps I should have called it MySubclassOfFileThatImplementsRunnable?

  • Cloneable Interface

    Hi,
    I know there have been lots of questions been posted for Cloneable being a marker interface .. but none off them has been satisfactory.
    my question is
    Clonable is a Marker interface. Object class has a protected method clone(). Now if we wish to override clone() method we must implement the cloneable interface but the cloneable interface doesnt define any such method.
    So how does one determine inorder to overide clone() method as defined in Object class, we need to implement Cloneable interface.

    'The method clone() for class Object performs a specific cloning operation', but that's the method clone() for class Object, isnt' it? There's nothing in the adjacent text or elsewhere to suggest that you can't or shouldn't implement a different behaviour, and plenty to suggest that you can.
    In fact there are many permissible behaviours:
    1. Do nothing. Object.clone() will throw CloneNotSupportedException.
    2. Implement Cloneable. Object.clone() will perform a shallow copy.
    3. Override clone(). Roll your own semantics.
    4. Override clone() and implement Cloneable. You can call super.clone().
    5. Override clone() and throw CloneNotSupportedException.
    6. Override clone(), implement Cloneable, and throw CloneNotSupportedException.
    Independently of all this you can also widen the access of clone() to public if you implement it.
    There may be others. None of these is excluded by any wording I can see in the JLS or the Javadoc for Object.clone().
    The reasons why clone() is protected not public, and is not defined in Cloneable, are 'lost in the mists of time' (Sun) but those who were around in 1997 will remember many discussions in which it was made clear that all the possible behaviours were intended to be supported. See the thread I quoted earlier.

  • Interface and Abstract class difference

    An interface can be used in such a way that we don't know the class of object assigned to a reference of that interface type until runtime. Can we use the abstract class in a similar way too?
    The difference between an abstract class and interface can be listed as
    1. Interface can not have implementation of any method
    2. The usage of interface and class is one other difference
    3. What other differences we have?

    Yes an abstract class can be used in a similar way. The main issue with an abstract class is that you extend it and you can only extend one class so that can be a huge limitation that an interface does not give you.
    Here's another one that is often overlooked: use both.
    public abstract class SomeBaseClass implements Runnable {
      public abstract void someAbstractMethod();
      public void someMethodWithADefaultImplementation(){
        System.out.println("Hello!");
    }Any class that extends SomeBaseClass (and is not abstract) will need to implement the run() method of the Runnable interface.

  • Difference between interface pool and class pool

    Hi,
    Can any body tell me the difference between Interface pool and Class pool.
    thank you in advance.
    regards

    Hi,
    Class and Interface Pools
    This section discusses the structure and special features of class and interface pools for global classes.
    Global Classes and Interfaces
    Classes and interfaces are object types. You can define them either globally in the Repository or locally in an ABAP program. If you define classes and interfaces globally, special ABAP programs called class pools or interface pools of type K or J serve as containers for the respective classes and interfaces. Each class or interface pool contains the definition of a single class or interface. The programs are automatically generated by the Class Builder when you create a class or interface.
    A class pool is comparable to a module pool or function group. It contains both declarative and executable ABAP statements, but cannot be started on its own. The runtime system can create runtime instances (objects) through a request using the CREATE OBJECT statement. These objects execute the statements of the class pool.
    Interface pools do not contain any executable statements. Instead, they are used as containers for interface definitions. When you implement an interface in a class, the interface definition is implicitly included in the class definition.
    Structure of a Class Pool
    Class pools are structured as follows:
    Class pools contain a definition part for type declarations, and the declaration and implementation parts of the class.
    Differences From Other ABAP Programs
    Class pools are different from other ABAP programs for the following reasons:
    ·        ABAP programs such as executable programs, module pools, or function modules, usually have a declaration part in which the global data for the program is defined. This data is visible in all of the processing blocks in the program. Class pools, on the other hand, have a definition part in which you can define data and object types, but no data objects or field symbols. The types that you define in a class pool are only visible in the implementation part of the global class.
    ·        The only processing blocks that you can use are the declaration part and implementation part of the global class. The implementation part may only implement the methods declared in the global class. You cannot use any of the other ABAP processing blocks (dialog modules, event blocks, subroutines, function modules).
    ·        The processing blocks of class pools are not controlled by the ABAP runtime environment. No events occur, and you cannot call any dialog modules or procedures. Class pools serve exclusively for class programming. You can only access the data and functions of a class using its interface.
    ·        Since events and dialog modules are not permitted in classes, you cannot process screens in classes. You cannot program lists and selection screens in classes, since they cannot react to the appropriate events. It is intended to make screens available in classes. Instead of dialog modules, it will be possible to call methods of the class from the screen flow logic.
    Local Classes in Class Pools
    The classes and interfaces that you define in the definition part of a class pool are not visible externally. Within the class pool, they have a similar function to local classes and interfaces in other ABAP programs. Local classes can only be instantiated in the methods of the global class. Since subroutines are not allowed in class pools, local classes are the only possible modularization unit in global classes. Local classes have roughly the same function for global classes as subroutines in function groups, but with the significant exception that they are not visible externally
    Reward points if useful....
    Regards
    AK

  • LDAP object class voilation

    Hello,
    When i am trying to provison the user details on to Sun one server i get an error as 65 LDAP : Object class voilation.
    Can any one help me in resolving the same...
    Regards,
    Raghu

    Raghu,
    Object Class violations occur when you try to add an attribute (that is, assign a value) that is not supported by the object classes specified in your ToLDAP pass.
    Try disabling all non-mandatory attributes and then re-enabling one at a time until you get the error.  This is your offending attribute.  You might also google for the schemas of the objectclasses you are using to get the same information.
    If the attribute you are trying to add does not exist in any objectclass then you will need to extend the objectclass schema.
    Hope this helps,
    Matt

  • Extending a class through inner anonymous class??

    What kind of construction is this?
    SomeClass sc = new SomeClass()
                      public void sayHello()
                        System.out.println("Hello");
              };I thought this is equal to sc extends SomeClass, and this is what the decompiled inner class tells. Anyhow I don't think this is the same as extending a class cause you can only overwrite methods which are declared/implemented in SomeClass, adding new methods doesn't make sense to compiler. If in the example above SomeClass doesn't contain sayHello method
    sc.sayHello();
    will result in compiler error message.

    The compiler error is because you are calling the method via a reference of type SomeClass, not a reference of the type of the anonyomous class you have created. If you need to do that, then use a named class.
    You can have any number of methods in an anonymous class, but you will only be able to call them from within the class itself unless they are declared in the superclass or super-interface.

  • Abstract class extends other class?

    What happens when a abstract class extends other class?
    How can we use the abstract class late in other class?
    Why do we need an abstract class that extends other class?
    for example:-
    public abstract class ABC extends EFG {
    public class EFG{
    private String name="";
    private int rollno="";
    private void setName(int name)
    this.name=name;
    private String getName()
    return this.name;
    }

    shafiur wrote:
    What happens when a abstract class extends other class?Nothing special. You have defined an abstract class.
    How can we use the abstract class late in other class?Define "Late". What "other class"?
    Why do we need an abstract class that extends other class?Because it can be useful to define one.

  • How to declare interface within a class

    1. I want to declare interface within a class. How can i do that & whats the advantage ?
    2. How to declare class within a interface ?
    Can anybody tell me the concept ?/
    Thanks in advance
    madhu

    Classes and interfaces are types.
    What is the advantage of declaring a type within another one?
    Do you know what is the advantage of declaring a class within another class?

  • What is object class?

    hi i am confused with the name? we can have so many object classes in the schema but why is the name object class? there can be class or there can be object but what is the meaning of object class?

    Thanks for all you replies guys. What ejp thought is right. As i am in the JNDI forum i thought people will understand my question in that context. if i am asking something about core java i would have posted my question in that particular forum. Any way if it lead to confusion i am sorry.
    Yes i am talking about LDAP attribute. I am confused with the name . the attribute can be simply calss rather than objectClass. I don't know why they have chosen the attribute name "objectclass" . This name just confused me. Any way thanks to you all.

Maybe you are looking for