10java Chapter1
10java Chapter1
Polymorphism:
Polymorphism comes from the Greek words “poly” and “morphism”. “poly”
means many and “morphism” means form i.e.. many forms. Polymorphism
means the ability to take more than one form.
Function overloading is the way to achieve polymorphism in java program
Example of polymorphism
class p1
{
public void area(int side)
{
int A1=side*side;
}
public void area(double radius)
{
int A2=3.14*radius*radius;
}
public void area(int L , int B)
{
int A3=L*B;
}
}
Inheritance:
Inheritance is the process by which one object can acquire the properties of
another. When the class child, inherits the class parent, the class child is
referred to as derived class (sub class) and the class parent as a base
class (super class).
class cal
{
add() // parent / super class
sub()
}
class cal_1.0 extend cal
{
avg() // child /sub / derived/ base
}
Tokens in Java:
In Java, a program is a collection of classes and methods, while methods
are a collection of various expressions and statements. Tokens in Java are
the small units of code which a Java compiler uses for constructing those
statements and expressions. Java supports 5 types of tokens which are:
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Special Symbols
1.Keywords
2.Identifier
Java Identifiers are the user-defined names of variables, methods,
classes, arrays, packages, and interfaces.
There are some standards which you must follow while naming the
identifiers such as:
3.Literals
Literals in Java are similar to normal variables but their values cannot be
changed once assigned. In other words, literals are constant variables with
fixed values. These are defined by users and can belong to any data type.
Java supports five types of literals which are as follows:
1. Integer
2. Floating Point
3. Character
4. String
5. Boolean
4.Operators
An operator in Java is a special symbol that signifies the compiler to
perform some specific mathematical or non-mathematical operations on
one or more operands. Java supports 6 types of operators. Below I have
listed down all the operators, along with their examples:
Operator Examples
Arithmetic +,–,/,*,%
Unary ++ , – – , !
Assignment = , += , -= , *= , /= , %= , ^=
Relational ==, != , < , >, <= , >=
Logical && , ||
Ternary (Condition) ? (Statement1) : (Statement2);
5.Special Symbols
Special symbols in Java are a few characters which have special meaning
known to Java compiler and cannot be used for any other purpose.
Symbol Description
These are used as an array element reference and also
Brackets []
indicates single and multidimensional subscripts
These indicate a function call along with function
Parentheses()
parameters
Braces{} The opening and ending curly braces indicate the
beginning and end of a block of code having more than
one statement
This helps in separating more than one statement in an
Comma ( , )
expression
Semi-Colon (;) This is used to invoke an initialization list
Asterisk (*) This is used to create a pointer variable in Java