Day 1
Day 1
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
01. abstract 02. boolean 03. byte 04. break 05. class
06. case 07. catch 08. char 09. continue 10. default
11. do 12. double 13. else 14. extends 15. final
16. finally 17. float 18. for 19. if 20. implements
21. import 22. instanceof 23. int 24. interface 25. long
26. native 27. new 28. package 29. private 30. protected
31. public 32. return 33. short 34. static 35. super
36. switch 37. synchronized 38. this 39. throw 40. throws
41. transient 42. try 43. void 44. volatile 45. while
46. assert 47. const 48. enum 49. goto 50. strictfp
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
The opening and ending curly braces indicate the
Braces{} 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