protected « subclass « Java Class Q&A

Home
Java Class Q&A
1.abstract class
2.Base class
3.class hierarchy
4.class name
5.class version
6.Class.forName
7.ClassCastException
8.Clone
9.constant
10.Constructor
11.Development
12.DTO
13.encapsulation
14.equal method
15.extend Class
16.getter
17.hashcode
18.Inheritance
19.inner class
20.interface
21.main class
22.Method
23.NoClassDefFoundError
24.NoSuchMethodError
25.NoSuchMethodException
26.object reference
27.overload
28.parent class
29.Polymorphism
30.private
31.Private Field
32.Recursive
33.setter
34.Static
35.Static Class
36.subclass
37.Super
38.toString
39.Wrapper Class
Java Class Q&A » subclass » protected 

1. How are java.lang.Object's protected methods protected from subclasses?    stackoverflow.com

The keyword protected grants access to classes in the same package and subclasses (http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html). Now, every class has java.lang.Object as superclass (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html). Hence I conclude that every class may ...

2. Use a subclass object to modify a protected propety within its superclass object    stackoverflow.com

Sorry for the crappy title I failed to think of a better version for my Java question. I am right now using Java version: 1.6.0_18 and Netbeans version: 6.8 Now for the question. What ...

3. Why can subclass not have PROTECTED ACCESS?    coderanch.com

Why can subclass not have PROTECTED ACCESS? public class Base {} public class Sub extends Base {} nicht zulssig, da in einem Source-File nur eine PUBLIC-Klasse sein darf Ist die Base-Klasse PUBLIC, dann darf die Sub-Klasse nur FRIENDLY als Zugriffsmodifier haben: public class Base {} class Sub extends Base {} //FRIENDLY ACCESS MODIFIER class Base {} protected class Sub extends ...

5. Protected method in a packaged superclass not being called by subclass    coderanch.com

I think I am getting somewhere with the following explanation, At compile time, b is treated as a Fruit object...Now calling k() on Fruit object is not possible because protected makes accessible only through inheritance. That's why when we assign it to Apple type it works fine... Let me know if I am correct here...

6. protected access method not accessible by subclass??    forums.oracle.com

The package is only related to the extent that protected access extends to the other package classes. Thus if it was the same package then the following would work. a.getS() Since it isn't the same package it doesn't work. The other part of protected is via derivation. But that code isn't using it in a derived manner (like inside a child ...

7. accessing static protected methods in Subclass    forums.oracle.com

Hi, Can we access static protected members of a class from one of its subclasses using a reference of the Superclass (assuming both the superclass and subclass are in different packages). If yes - please explain. package p1; public class Base { protected static void method1() { System.out.println("Base"); } } package p2; public class Child extends Base{ public static void main(String[] ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.