What is java
What is java
Data-types ;
1. primitive data types byte, short ,int long,boolean.double.float,char.
2. Objective data types String
What is variable ?
Its stores value example double price=12.55; (DOUBLE=DATATYPE , PRICE
VARIBLE ,123=VALUE
For local variablename and instance variable name is same first preference to local variable.
If you wants still call instance variable we can use this.variablename
If current class instance variablename and super class instance variable name is same we have to use
super keyword super.variablename
METHODS
1. Instance methods
2. Static methods
1 Instance method
Public String name(){
Return “ ramesh”}
Public is access modifier String is return type name is methodname return is return statement
Above method is instance method
For calling instance method we need to create instance or object
We cant override private and final methods
Static method
If you are adding the static keyword to instance method which static method
We can call static methods classname.methodname();
we cant override static method
Which stored in method area
Inheritance
To acquiring super class data into subclass.
We denotes inheritance by extends keyword
If you can create object to for subclass you can able to access all super class data
and sub class data
If you create object for super class we can able to access only super class data
only
If you create super class reference and subclass object you cant access subclass
specific methods
Final class cant extends
Class to class A extends B
Class to interface redbus Implements phoneype.
Interface to interface extends
Interface to class not possible
Sub class is HDFC
And parent class is cred
Grand parent t class is bill desk
Grand parent
Polymorphism:
It is two types
1. compile time polymorphism (method overloading)
2. Runtime polymorphism (method overriding)
1 METHOD OVERLOADING;
Methods name is same but parameters list are different in same class
Ethier number of parametrs list are different ,or data types are diffrenrt or order of parameters are
different
OVERRIDDING
If method name is same and parameters also same in two different classes
We cant override private final and static methods
INTERFACE;
Which hides data , which is pure abstract class
By using interface we can achive multiple inheritance
We can provide implementation in childe class only
We cant create object for interface
By default method are public and abstract where you declare are not
By defaults variables are public static final
We can write only abstract methos (non -concrate)
We cant write concreate methods
We cant write constructor
We cant write instance blocks and static blocks
Abstract:
Abstract is a keyword
Showing necessary data and hideing unnecessary data
By adding abstract keyword to class we can make class as a abstract
We can provide implementation for the abstract class in child class
only
We cant create object for abstract class
It allows abstract methods and non abstract methods
Its allows instance blocks and static blocks
We can create constructor for abstract class
Encapsulation;
Encapsulation means protecting data in a class
By creation private properties and public setters and getters methods
Constructor
Constructor is for initializing the data
In object it contains constructor
Constructor should be with a classname and which dosent have any return type
Ts is two types
1 No argument constructor
2 argument constructor
By default java will provide argyument aconstructor in class the default constructor will be over
ride
If you still want zero argument constructor you have to provide manually\
Diffrence between throws throw throwable ??
With throw we can create our coustome exception
With throws we can do the declaration of the exception
Throwable is super class of all exceptions classes
Access modifiers
EXCDEPTIONS
For that we have to create private static variable it will create private constructor so that we avoid the
initialization in other class