EECS 40 Lecture Notes - Lecture 9: Function Overloading

51 views4 pages
EECS 40
WK5 Lec 9
Access Levels & Modifiers
- In order of how restrictive they are, from least to most restrictive.
public
public means any code anywhere can access the public thing (by
thing we mean class, variable, method, constructor, etc).
protected
protected works just like default (code in the same package has
access), EXCEPT it also allows subclasses outside the package to inherit
the protected thing.
default
default access means that only code within the same package as the
class with the default thing can access the default thing.
private
private means that only code within the same class can access the
private thing. Keep in mind it means private to the class, not private to
the object. One Dog can see another Dog objects private staff, but a
Cat cant see a Dogs privates.
Modifier
Class
Package
Subclass
World
public
Y
Y
Y
Y
protected
Y
Y
Y
N
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Keep in mind it means private to the class, not private to the object. One dog can see another dog object(cid:23563)s private staff, but a. Singleton class design pattern import java. io. class mysingleton{ static mysingleton instance = null; public int x = 10; // private constructor can"t be access outside the class private mysingleton(){ //factory method to provide users with instances static public mysingleton getinstance(){ if(instance==null){ instance = new mysingleton(); return instance; As the name implies, a class is said to be singleton if it limits the number of objects of that class to one. We can(cid:23563)t have more than a single object for such classes. Singleton classes are employed extensively in concepts like. With polymorphism, the reference and the object can be different. When you override a method from a superclass, the arguments and return types of your overriding method must look to the outside world exactly like the overrides method in the superclass.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents