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 )
4. 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.");
}
}
5. class Bank
{
int accountBalance ;
public Bank(){
accountbalance = 10000;
}
Synchronized void BalanceInquiry(){
System.out.println(“account
balance is :”+accountbalance);
}
}
6. abstract class Hotel
{
public void Idli(){
System.out.println(“Prepare Idli”);
}
abstract public void Dosa();
}
7. 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();
}
}
16. 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
17.
18.
19.
20.
21.
22.
23.
24.
25. 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
26. public class Test{
public static void main(String args[])
{
int a, b;
a = 10;
b = 20;
( a > b ) ? a : b ;
( a <10 ) ? a : b ;
}
}
27. 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.