Showing posts with label Interface. Show all posts
Showing posts with label Interface. Show all posts

Monday, 28 November 2011

Operators and assignments

Using operators - 1


Assignment operators


You can assign a primitive variable using a literal or the result of an expression. The result of an expression involving integers (int, short, and byte) is always at least of type int. Narrowing conversions are not allowed, as they would result in the loss of precision. For instance:

byte b = 5;
byte c = 4;
byte d = b + c;               // does not compile because int cannot fit in a byte


float f = (float)35.67;   // implicitly double, so casting to float
float f = 35.67F;


A boolean cannot be assigned any type other than boolean.

If we assign an existing object reference to a reference variable, both reference variables refer to the same object. It is legal to assign

Saturday, 19 November 2011

Sun Certified Java Programmer (SCJP)

Interfaces


An interface is like a public class that has only abstract and public methods. The variables declared in an interface are implicitly public, static, and final. For instance:

interface MyInterface
{


void f();


}


class MyClass implements MyInterface
{


public void f() {}


}


A concrete class implementing an interface has to implement all the methods declared in it.

Interface methods are implicitly public and cannot be declared