Post a Job  |   Ask a Question?   |   Already registered? login or register
Ramakanth reddy
14/05/2015 03:45 AM

I am sending details about protected access modifier


I am sending details about protected access modifier
Spam    1 Comments

Ramakanth,reddy
14/05/2015 03:45:59
1.a)In same package: ============ In same package u can use any where .That's no problem. 1.b)in Differnt pacakge case: ================== plz See this code ....................... package com.prt.a; class A{ //super class protected m1(){ System.out.println("a.m1()"); } } package com.prt.b; class B extends A{ public static void main(String[] args){ A a=new B().m1();------------------>[Not Applicable]=====>line1 B b=new B().m1();------------------>[Applicable]=====>line2 } } if at all if you want to use protected method of super class(class A) in your child(class B) of differnt pacakage then dont use super reference to hold your child class object inside child class if you use super reference (class A)to hold your child class object inside child class(class B) of differnt pacakage (LINE -1 in above code), on that reference you can't call super class protected method . But if you use child reference(class B) to hold your child class object (LINE -2 in abobe code) inside child class(class B) , on that reference you can call super class protected method .

Languages :
xml