Dynamic class in Java
We realize that each java program must begin with an idea of class that is without classes idea there is no java program great.
In java programming we have two sorts of classes they are
- Solid class
- Dynamic class
- Solid class in Java
A solid class is one which is containing completely characterized techniques or actualized strategy.
Example
class Helloworld { void display() { System.out.println("Good Morning........"); } }
Here Helloworld class is containing a defined method and object can be created directly.
Create an object
Helloworld obj=new Helloworld(); obj.display();
Each solid class have particular component and these classes are utilized for particular necessity yet not for regular prerequisite.
On the off chance that we utilize solid classes for satisfy normal necessities than such application will get the accompanying restrictions.
- Application will take more measure of memory space (fundamental memory).
- Application execution time is more.
- Application execution is diminished.
To overcome above confinement you can utilize theoretical class.
Dynamic class in Java
A class that is proclaimed with conceptual watchword, is known as dynamic class. A unique class is one which is containing some characterized strategy and some unclear technique. In java programming unclear strategies are known as un-Executed or theoretical strategy.
Syntax
abstract class className { ...... }
Example
abstract class A { ..... }
If any class have any abstract method then that class become an abstract class.
Example
class Vachile { abstract void Bike(); }
Class Vachile is become an abstract class because it have abstract Bike() method.
Make class as abstract class
To make the class as abstract class, whose definition must be preceded by a abstract keyword.
Example
abstract class Vachile { ...... }
Syntax
abstract ReturnType methodName(List of formal parameter)
Example
abstract void sum();
abstract void diff(int, int);
abstract void diff(int, int);
Example of abstract class
abstract class Vachile { abstract void speed(); // abstract method } class Bike extends Vachile { void speed() { System.out.println("Speed limit is 40 km/hr.."); } public static void main(String args[]) { Vachile obj = new Bike(); //indirect object creation obj.speed(); } }
Output
Speed limit is 40 km/hr..
Make an Object of dynamic class
An object of dynamic class can not be made specifically but rather it can be made in a roundabout way. It implies you can make an object of unique inferred class. You can see in above case
Illustration
Vachile obj = new Bicycle();/backhanded article creation
Critical Focuses about conceptual class
Dynamic class of java dependably contains regular components.Each conceptual class take an interest in legacy.
Conceptual classes definitions ought not be made as last since unique classes dependably take an interest in legacy classes.
An object of unique class can not be made specifically but rather it can be made in a roundabout way.
All the conceptual classes of java makes utilization of polymorphism alongside strategy superseding for business rationale advancement and makes utilization of element authoritative for execution rationale.
Favorable position of theoretical class
- Less memory space for the application
- Less execution time
- More execution
Why dynamic class have no theoretical static technique ?
In dynamic classes we have just theoretical case technique yet not containing conceptual static strategies in light of the fact that each case strategy is made for performing rehashed operation where as static technique is made for performing one time operations in other word each unique strategy is example however not static.
Conceptual base class
A conceptual base class is one which is containing physical representation of dynamic techniques which are acquired by different sub classes.
Conceptual determined class
A conceptual determined class is one which is containing rationale representation of dynamic strategies which are acquired from theoretical base class regarding both unique base class and unique inferred class one can not make object s straightforwardly but rather we can make there articles by implication both conceptual base class and theoretical inferred class are constantly reusable by different sub classes.
At the point when the inferred class acquires various conceptual strategy from theoretical base class and if the determined class is not characterizing no less than one dynamic technique then the inferred class is known as unique determined class and whose definition must be made as unique by utilizing dynamic catchphrase. (At the point when the determined class turn into a theoretical inferred class).
On the off chance that the determined class characterized all the unique techniques which are acquired structure dynamic Base class then the inferred class is known as concrete determined class.
Example of abstract class having method body
abstract class Vachile { abstract void speed(); void mileage() { System.out.println("Mileage is 60 km/ltr.."); } } class Bike extends Vachile { void speed() { System.out.println("Speed limit is 40 km/hr.."); } public static void main(String args[]) { Vachile obj = new Bike(); obj.speed(); obj.mileage(); } }
Output
Mileage is 60 km/ltr..
Speed limit is 40 km/hr..
Speed limit is 40 km/hr..
Example of abstract class having constructor, data member, methods
abstract class Vachile { int limit=40; Vachile() { System.out.println("constructor is invoked"); } void getDetails() { System.out.println("it has two wheels"); } abstract void run(); } class Bike extends Vachile { void run() { System.out.println("running safely.."); } public static void main(String args[]) { Vachile obj = new Bike(); obj.run(); obj.getDetails(); System.out.println(obj.limit); } }
Output
constructor is invoked
running safely..
it has two wheels
40
running safely..
it has two wheels
40