Contents
super keyword in java
Â
The super keyword in Java is a footnote variable which is used to refer to the time root of class object.
Whenever you produce the instance of a subclass, an instance of the root of the class is produced implicitly which is referred to by the super footnote variable.
Usage of Java Super Keyword
Â
- super can be used to refer to the time root of the class instance
- super can be used to produce at the time root of class way(method).
- super() can be used to produce at the time root of the class
super is used to refer to the time root of the class instance variable.
Â
class programmer{
String color=”green”;
}
class coding expand progemar{ String color=”black”;
void printColor(){ System.out.println(color);//prints color of Dog class
System.out.println(super.color);//prints color of programer class
}
}
class TestSuper1{
public static void main(String args[]){ Dog d=new Dog();
d.printColor();
}}
Output:
black green |
Final Keyword in Java
Â
The final keyword in java is used to limit the user. The java final keyword can be used in a lot of context. Final can be:
- variable
- way(method)
- class
The final keyword can be useable with the variables, a final variable that have no value it is called blank final variable or unestablished final variable. It can be established in the creater only. The blank final variable can be static also which will be established in the static block only.
Object class in Java
Â
The Object class is the root of  class of all the classes in java by default. In other words, it is the topmost class of java.
The Object class is beneficial if you want to refer any object whose type you don’t know. Notice that root of  class footnote variable can refer the child class object, know as up casting.
Let’s take an example, there is getObject() way(method) Â that returns an object but it can be of any type like worker,Coding etc, we can use Object class footnote to refer that object. For example:
- Object obj=getObject();//we don’t know what object will be returned from this way(method)
The Object class gives some frequentway(method) ss to all the objects such as object can be            compared, object can be cloned, object can be notified etc.
Way(method) Â Overriding in Java
Â
If subclass (child class) has the same way(method)  as said in the root of  class, it is known as way(method)  overriding in java.
Usage of Java Way(method) Â Overriding
- Way(method) overriding is used to provide specific fulfilment of a way(method)  that is already  provided by its super
- Way(method) overriding is used for runtime polymorphism
Rules for Java Way(method) Â Overriding
- way(method) must have same name as in the root of  class
- way(method) must have same parameter as in the root of
- must be IS-A correlation (inheritance).
Example of way(method) Â overriding Class Vehicle{
void run(){System.out.println(“programercodeing.com”);}
}
class Bike2 expand Vehicle{
void run(){System.out.println(“we are working safely on programercodeing “);}
public static void main(String args[]){ Bike2 obj = new Bike2();
obj.run();
}
Output: we are working safely on programercodeing
- class Bank{
int getRateOfInterest(){return 0;}
}
class SBI expand Bank{
int getRateOfInterest(){return 8;}
}
class ICICI expand Bank{
int getRateOfInterest(){return 7;}
}
class AXIS expand Bank{
int getRateOfInterest(){return 9;}
}
class Test2{
public static void main(String args[]){ SBI s=new SBI();
ICICI i=new ICICI(); AXIS a=new AXIS();
System.out.println(“SBI Rate of Interest: “+s.getRateOfInterest()); System.out.println(“ICICI Rate of Interest: “+i.getRateOfInterest()); System.out.println(“AXIS Rate of Interest: “+a.getRateOfInterest());
} }
Output:
SBI Rate of Interest: 8 ICICI Rate of Interest: 7 AXIS Rate of Interest: 9 |
Conceptual class in Java
Â
A class that is said with conceptual keyword is known as conceptual class in java. It can have conceptual and non-conceptual way(method) Â (way(method) with body). It needs to be extended(drawn out in length especially of time) and its way(method) Â applied. It cannot be complete.
Example conceptual class
- conceptual class A{}
conceptual way(method)
- conceptual void printStatus();//no body and conceptual
Example of conceptual class that has conceptual way(method)
conceptual class Bike{
conceptual void run();
}
class Honda4 expand Bike{
void run(){System.out.println(“progermercoding.com.”);}
public static void main(String args[]){ Bike obj = new Honda4();
obj.run();
}
progermercoding.com. |
- }
Borderline in Java
An borderline in java is a strategy of a class. It has static constants and conceptual way(method) s.
The borderline in java is a tool to gain conceptualion. There can be only conceptual way(method) s in the java borderline not way(method) Â body. It is used to gain conceptualion and multiple inheritance in Java.
Java Borderline also represents IS-A correlation. It cannot be complete just like conceptual class.
There are mainly three reasons to use borderline. They are given below.
- It is used to gain
- By borderline, we can pillar the convenience of multiple
- It can be used to gain loose coupling.
//Borderline announcement: by first user
borderline Drawable{
void draw();
}
//Fulfilment: by second user
class Rectangle applies Drawable{
public void draw(){System.out.println(“progemarcoding.com”);}
}
class Circle applies Drawable{
public void draw(){System.out.println(“progemarcoding.com “);}
}
//Using borderline: by third user
class TestBorderline1{
public static void main(String args[]){
Drawable d=new Circle();//In real scenario, object is provided by way(method) Â e.g. getDrawable() d.draw();
}}
Output: progemarcoding.com
Multiple inheritance in Java by borderline
Â
borderline Printable{
void print();
}
borderline Showable{
void show();
}
class A7 applies Printable,Showable{
public void print(){System.out.println(“Hello”);} public void show(){System.out.println(“Welcome”);} public static void main(String args[]){
A7 obj = new A7(); obj.print();
obj.show();
} }
Output:Hello
Welcome |
|||||||
Conceptual class | Borderline | ||||||
1) Conceptual class can have conceptual and non-conceptual way(method) s. | Borderline can have only conceptual way(method) s. Since Java 8, it can have default and static way(method) s also. | ||||||
2)   Conceptual                        class doesn’t            pillar multiple inheritance. | Borderline pillars multiple inheritance. | ||||||
3) Conceptual class can have final, non- final, static and non-static variables. | Borderline has only static and final variables. | ||||||
4)  Conceptual                class can      provide   the fulfilment of borderline. | Borderline can’t provide the fulfilment of conceptual class. | ||||||
5) The conceptual keyword is used to declare conceptual class. | The borderline keyword is borderline. | used | to   declare | ||||
6) Example:
public                conceptual public                 conceptual } |
class void |
Shape{ draw(); |
Example:
public                            borderline void } |
Drawable{ draw(); |
Java Inner Classes
Java inner class or nested class is a class which is said inside the class or borderline.
We use inner classes to naturally group classes and borderlines in one place so that it can be more                         legible and acceptable.
Syntax of Inner class
- class Java_Outer_class{
- //code
- class Java_Inner_class{
- //code
- } }
Advantage of java inner classes
Â
There are basically three advantages of inner classes in java. They are as follows:
- Nested classes represent a specific type of correlation that is it can entrance all the members (data members and way(method) s) of outer class including
- Nested classes are used to develop more legible and acceptable code because it naturally group classes and borderlines in one place
- Code Optimization: It needs less code to
Difference between nested class and inner class in Java
Inner class is a part of nested class. Non-static nested classes are known as inner classes.
Types of Nested classes
Â
There are two types of nested classes non-static and static nested classes.The non-static nested classes are also known as inner classes.
- Non-static nested class (inner class)
- Member inner class
- Anonymous inner class
- Local inner class
- Static nested class
Java Package
A java package is a group of similar types of classes, borderlines and sub-packages. Package in java can be categorized in two form, built-in (who is already builted) package and user-circle package. There are a lot of built-in (who is already builted) packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
Advantage of Java Package
- Java package is used to categorize the classes and borderlines so that they can be easily
- Java package gives entrance protection.
- Java package removes naming
package mypack;
public class Simple{
public static void main(String args[]){ System.out.println(“Welcome to our web”);
} }
How to compile java package
If you are not using any IDE, you need to follow the syntax given below: javac -d directory javafilename
How to run java package program
Â
To Compile: javac -d . Simple.java
To Run: java mypack.Simple
Using fully qualified name
Â
Example of package by import fully qualified name
//save by A.java package pack; public class A{
public void msg(){System.out.println(“Hello welcome to our web”);} }
//save by B.java package mypack; class B{
public static void main(String args[]){
pack.A obj = new pack.A();//using fully qualified name obj.msg();
}
}
 Output:Hello welcome to our web