In Java, final is the access modifier which can be used with a filed, class and a method.When a method if final it cannot be overridden.When a variable is final its value cannot be modified further.When a class is final it cannot be extended.Initializing a final variableOnce you declare a final variable, it is a must to initialize it. You can initialize the final instance variable −At the time of declaration as.public final String name = "Raju"; public final int age = 20;Within an instance (non-static) block.{ this.name = "Raju"; this.age = 20; }Within a default constructor.public final ... Read More
In Java final is the access modifier which can be used with a filed class and a method.When a method if final it cannot be overridden.When a variable is final its value cannot be modified further.When a class is final it cannot be extended.Declaring final variable without initializationIf you declare a variable as final, it is mandatory to initialize it before the end of the constructor. If you don’t, a compile-time error is generated.Example Live Demopublic class Student { public final String name; public final int age; public void display(){ System.out.println("Name of the Student: "+this.name); ... Read More
A constructor is used to initialize an object when it is created. It is syntactically similar to a method. The difference is that the constructors have the same name as their class and, have no return type.There is no need to invoke constructors explicitly these are automatically invoked at the time of instantiation.Example Live Demopublic class Example { public Example(){ System.out.println("This is the constructor of the class example"); } public static void main(String args[]) { Example obj = new Example(); } }OutputThis is the constructor of the class exampleFinal methodWhenever you ... Read More
PHP allows the user to modify some of its settings mentioned in php.ini using ini_set(). This function requires two string arguments. The first one is the name of the setting to be modified and the second one is the new value to be assigned to it.Parametersvar nameNot all the available options can be changed using ini_set(). There is a list of all available options in the appendix.new valueThe new value for the option.ExampleGiven the line of code will enable the display_error setting for the script if it’s disabled. We need to put the above statement, at the top of the ... Read More
Basically, PHP is interpreted but PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime Zend engine.PHP compiler is responsible forconvert the code to a bytecode that can be used by the runtime engine.resolve functions, names and classes namescreating a symbol tablePHP Interpreter doesGoes through the bytecode line by line and executes itHandles runtime exception
Let's discuss the differences between errors and exceptions.Recovering from Error is not possible. The only solution to errors is to terminate the execution. Whereas we can recover from Exception by using either try-catch blocks or throwing an exception back to the caller.You will not be able to handle the Errors using try-catch blocks. Even if you handle them using try-catch blocks, your application will not recover if they happen. On the other hand, Exceptions can be handled using try-catch blocks and can make program flow normally if they happen.Exceptions are related to the application whereas Errors are related to the ... Read More
Re-declaring a variable will not destroy the value of a variable, until and unless it is assigned with some other new value.If we look at the following example variables "x" and ''y'' were assigned with values 4 and 8 respectively, later on when those variables were reassigned, the old values were replaced with the new values and displayed as shown in the output.ExampleLive Demo var x = new Number(4); var x = 7; var y = 8; var y = 10; document.write(x); ... Read More
A super keyword is a reference of the superclass object in Java. Using this, you can invoke the instance methods constructors and, variables, of a superclass.Calling the constructor of a superclassYou can call the constructor of a superclass from the subclass’s constructor.ExampleConsider the following example, it has two classes SuperClass class and SubClass where the SubClass extends the SuperClass. The superclass has a parameterized constructor, we are invoking it from the subclass using the "super" keyword. Live Democlass SuperClass{ SuperClass(int data){ System.out.println("Superclass's constructor: "+data); } } public class SubClass extends SuperClass{ SubClass(int data) { ... Read More
Inheritance can be defined as the process where one (parent/super) class acquires the properties (methods and fields) of another (child/sub). With the use of inheritance, the information is made manageable in a hierarchical order. The class which inherits the properties is known as a subclass and the class whose properties are inherited is called superclass. In short, in inheritance, you can access the members (variables and methods) of the superclass using the subclass object.Example Live Democlass SuperClass { public void display(){ System.out.println("Hello this is the method of the superclass"); } } public class SubClass extends SuperClass ... Read More
A static method is the one which you can call without instantiating the class. If you want to call a static method of the superclass, you can call it directly using the class name.Example Live Demopublic class Sample{ public static void display(){ System.out.println("This is the static method........"); } public static void main(String args[]){ Sample.display(); } }OutputThis is the static method........It also works, if you call a static method using an instance. But, it is not recommended. Live Demopublic class Sample{ public static void display(){ System.out.println("This is the static ... Read More