Date post: | 10-Jul-2015 |
Category: |
Education |
Upload: | shridhar-ramesh |
View: | 129 times |
Download: | 0 times |
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 inall subclasses.
Methods declared protected in a superclass must either beprotected or public in subclasses; they cannot be private.
Methods declared without access control (no modifier wasused) can be declared more private in subclasses.
Methods declared private are not inherited at all, so there is norule for them.