Java(Access Modifiers)

80 %
20 %
Information about Java(Access Modifiers)
Education

Published on September 17, 2014

Author: ShridharRamesh

Source: slideshare.net

Description

Private(Class Access) Public(Global Access) Default(Package Level Access) Protected(Inside the same Package and in the outside package we can access but based on only inhertance relationship )

 Final  Synchronized  Abstract  static

 The final keyword prevents a method from being overridden in a subclass class SuperClass{ public final void showSample() { System.out.println("One thing."); } } class SubClass extends SuperClass{ public void showSample() { // Try to override the final // superclass method System.out.println("Another thing."); } }

class Bank { int accountBalance ; public Bank(){ accountbalance = 10000; } Synchronized void BalanceInquiry(){ System.out.println(“account balance is :”+accountbalance); } }

abstract class Hotel { public void Idli(){ System.out.println(“Prepare Idli”); } abstract public void Dosa(); }

class Pageview { public static final int count = 0; public Pageview() { count++; System.out.println(“Number of views to website”+count); } public static void main(String args[]) { Pageview p = new Pageview(); } }

 Arithmetic Operators  Relational Operators  Bitwise Operators  Logical Operators  Assignment Operators

 Bitwise operator works on bits and performs bit-by-bit operation. Assume if a = 60; and b = 13; now in binary format they will be as follows:  a = 0011 1100  b = 0000 1101  ------------------------------------------------------------------------------------------  a & b = 0000 1100  a || b = 0011 1101  a ^ b = 0011 0001  ~a = 1100 0011

 Conditional Operators are also called ternary operator  This operator consists of three operands.  It is used to evaluate an expressions  Syntax: variable x = (expression) ? value if true : value if false

public class Test{ public static void main(String args[]) { int a, b; a = 10; b = 20; ( a > b ) ? a : b ; ( a <10 ) ? a : b ; } }

 Methods declared public in a superclass also must be public in all subclasses.  Methods declared protected in a superclass must either be protected or public in subclasses; they cannot be private.  Methods declared without access control (no modifier was used) can be declared more private in subclasses.  Methods declared private are not inherited at all, so there is no rule for them.

Add a comment

Related presentations

Related pages

Controlling Access to Members of a Class (The Java ...

Access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control:
Read more

Access modifiers in java - Javatpoint

Access modifiers in java or java access modifiers such as private, default, protected and public with examples applied on data member, method, constructor ...
Read more

Access Modifiers In Java - Java Tutorial Blog

Access modifiers specifies who can access them. There are four access modifiers used in java. They are public, private, protected, no modifer (declaring wi
Read more

Java Access Modifiers - Jenkov.com

Each of these Java access modifiers will be covered in the following sections. Assigning an access modifier to a class, constructor, field or method is ...
Read more

Access Modifiers - java-forum.org

Diskutiere Access Modifiers im Forum Java Basics - Anfänger-Themen - Hallo! Da meine letzte Frage innerhalb von 2 Minuten sofort korrekt ...
Read more

Java - Access Modifiers - Tutorialspoint

Java provides a number of access modifiers to set access levels for classes, variables, methods, and constructors. The four access levels are −
Read more

access modifiers - java-forum.org

Diskutiere access modifiers im Forum Java Basics - Anfänger-Themen - Hallo zusammen. Ich bin in unserem Code hier auf lokale Klassen und Methoden ...
Read more

Java - Modifier Types - Tutorialspoint

Java Modifier Types - Learn Java in simple and easy steps starting from basic to advanced concepts with examples including Java Syntax Object Oriented ...
Read more

Access Modifiers (C# Programming Guide) (MSDN)

Access Modifiers. Access ... Access from another assembly must take ... Destructors cannot have accessibility modifiers. To set the access level for a ...
Read more

Access Modifiers (C# Reference) - msdn.microsoft.com

Access modifiers are keywords used to specify the declared accessibility of a member or a type. This section introduces the four access modifiers:
Read more