Found 9150 Articles for Object Oriented Programming

How many types of inheritance are there in Python?

Sri
Sri
Updated on 29-Jun-2020 11:16:47

415 Views

Inheritance is concept where one class accesses the methods and properties of another class.Parent class is the class being inherited from, also called base class.Child class is the class that inherits from another class, also called derived class.There are two types of inheritance in python −Multiple InheritanceMultilevel InheritanceMultiple Inheritance −In multiple inheritance one child class can inherit multiple parent classes.Exampleclass Father:    fathername = ""    def father(self):       print(self.fathername) class Mother:    mothername = ""    def mother(self):       print(self.mothername) class Daughter(Father, Mother):    def parent(self):       print("Father :", self.fathername)     ... Read More

How to call parent constructor in child class in PHP?

Alok Prasad
Updated on 29-Jun-2020 11:06:57

4K+ Views

We will face two cases while calling the parent constructor method in child class.Case1We can't run directly the parent class constructor in child class if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required.Example Live DemoOutput: I am in Tutorials Point I am not in Tutorials PointExplanationIn the above example, we have used parent::__construct() to call the parent class constructor.Case2If the child does not define a constructor then it may be inherited from the parent class just like a normal class method(if it was not declared as ... Read More

What is the use of Object.is() method in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

193 Views

Object.is()Object.is() is used to check whether two values are same or not. Two values are same when they have the following criteria. Either both the values are undefined or null .Either both are true or false.Both strings should be of same length, same characters and in same order.The polarities of both the values should be equal.Both the values can be NaN and should be equal.syntaxObject.is(val1, val2);It accepts two parameters and scrutinize whether they are equal or not. If equal gives out true as output else false as output.There is a small difference between Object.is() and "==" that is when comparing +0 and -0, the former results false whereas the latter results true. ... Read More

How to handle the NumberFormatException (unchecked) in Java?

Shriansh Kumar
Updated on 27-May-2025 10:50:11

2K+ Views

The NumberFormatException is a class that represents an unchecked exception thrown by parseXXX() methods when they are unable to format (convert) a string into a number. Here, the parseXXX() is a group of Java built-in methods that are used to convert string representations of numbers into their corresponding primitive data types. Causes for NumberFormatException in Java The NumberFormatException extends IllegalArgumentException class of java.lang package. It can be thrown by many methods/constructors of the classes. Following are some of them: int parseInt(String s): It throws NumberFormatException if ... Read More

How to handle the ArithmeticException (unchecked) in Java?

Shriansh Kumar
Updated on 27-May-2025 11:31:15

7K+ Views

Java ArithmeticException The ArithmeticException of java.lang package is an unchecked exception in Java. It is raised when an attempt is made to use a wrong mathematical expression in the Java program. An example of ArithmeticExeption is division by 0. If you divide two numbers and the number in the denominator is zero. The Java Virtual Machine will throw ArithmeticException. Example: Throwing ArithmeticException In the following Java program, we try a mathematical operation where we divide a number by 0. public class ArithmeticExceptionTest { public static void main(String[] args) { int a ... Read More

How to add two strings with a space in first string in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:10:23

5K+ Views

To add two strings we need a '+' operator to create some space between the strings, but when the first string itself has a space with in it, there is no need to assign space explicitly. In the following example since the string 'str1' has a space with in it, just only concatenation without space is adequate to add both the strings.ExampleLive Demo           function str(str1, str2) {          return (str1 + str2);       }       document.write(str("tutorix is the best ", "e-learning platform"));     Outputtutorix is the best ... Read More

What are the differences between protected and default access specifiers in Java?

Shriansh Kumar
Updated on 16-Apr-2025 18:59:58

11K+ Views

The protected and default access modifiers determine how a member of a class or method can be accessed. The modifiers are attached to the members at the time of declaration. Since Java follows the object-oriented programming paradigm, these access modifiers are used in encapsulation, polymorphism, and inheritance to control the behavior of class members. We will try to understand the difference between protected and default access modifiers in Java through this article. Protected Access Modifier The protected access modifier is mostly used in the case of inheritance to control the access of parent class members and corresponding child class members. ... Read More

How to parse an URL in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

384 Views

Parsing an URLIt is very simple to parse an URL in javascript by using DOM method rather than Regular expressions. If regular expressions are used then code will be much more complicated. In DOM method just a function call will return the parsed URL. In the following example, initially a function is created and then an anchor tag "a" is created inside it using a DOM method. Later on the provided URL was assigned to the anchor tag using href. Now, when function returns the parts of the URL, it tries to return the parsed parts as shown in the output. ... Read More

What is an OutOfMemoryError and steps to find the root cause of OOM in Java?

raja
Updated on 24-Feb-2020 11:27:10

2K+ Views

The OutOfMemoryError is thrown by JVM, when JVM does not have enough available memory, to allocate. OutOfMemoryError falls into the Error category in Exception class hierarchy.To generate OutOfMemoryErrorWe will allocate a large chunk of memory, which will exhaust heap memory storage.We will keep on allocating the memory and point will reach, when JVM will not have enough memory to allocate, then OutOfMemoryError will be thrown.Once we will catch the OutOfMemory error, we can log the error.ExampleLive Demopublic class OutOfMemoryErrorDemo {    public static void main(String[] args) throws Exception {       int dummyArraySize = 15;       System.out.println("Max JVM memory: " + Runtime.getRuntime().maxMemory()); ... Read More

Can we write any code after throw statement in Java?

Shriansh Kumar
Updated on 16-May-2025 18:29:43

2K+ Views

No, we can not place any code after throw statement, it leads to compile time error. The compiler will show this error as unreachable statement. In Java, the throw statement immediately terminates the current flow of execution, therefore, the code immediate to a throw statement will not be executed. The control is then transferred to the next catch block or the caller method. The throw Keyword in Java The throw keyword is used to throw an exception manually. Whenever it is required to stop the execution of the functionality based on the user-defined logical error condition, we will use this ... Read More

Advertisements