-
Junior Member
Over riding methods of non subclass
Hi Friends,
Can any one help me to know it clearly.
Following is a small program for illustartion that we can override the built in methods. Its works fine, I am not getting it clearly that how it overrides the method of a non-subclass .
/* defination of overridng: the concept of over-riding means we are having the same signature for the methods in the base & sub-classes which extends the base class. here str1 is not extension of String*/
class str1
{
String str="Hello World";
public char charAt(int a) // overrides charAt method of class String
//of java.lang package
{
return (char)a;
}
}
class test1
{
public static void main(String arg[])
{
str1 obj=new str1();
String S="Hello World";
System.out.println("by overriding"+obj.charAt(4)+"n using stad method"+S.charAt(4));
}
}
Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules