- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34494 Articles for Programming
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
517 Views
The this is a keyword in Java which is used as a reference to the object of the current class. Using it you can − Differentiate the instance variables from local variables if they have same names, within a constructor or a method. Call one type of constructor (parametrized constructor or default) from other in a class. It is known as explicit constructor invocation. Example class Superclass { int age; Superclass(int age) { this.age = age; } public void ... Read More
![Monica Mona](https://www.tutorialspoint.com/assets/profiles/13520/profile/60_87298-1512650151.jpg)
3K+ Views
No, constructors cannot be inherited in Java. In inheritance sub class inherits the members of a super class except constructors. In other words, constructors cannot be inherited in Java therefore, there is no need to write final before constructors. Example public interface InterfaceTest { public InterfaceTest(){ } public abstract void display(); public abstract void show(); } Still, if you try to write constructors in an interface it will generate a compile time error. Error C:\Sample>javac InterfaceTest.java InterfaceTest.java:2: error: expected InterfaceTest(){ ^ 1 error C:\Sample>
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
541 Views
No, interfaces can’t have constructors for the following reasons − All the members of an interface are abstract, and since a constructor cannot be abstract. Still, if you try to write a constructor within an interface it will generate a compile time error. Example public interface InterfaceTest { InterfaceTest(){ } public abstract void display(); public abstract void show(); } Error C:\Sample>javac InterfaceTest.java InterfaceTest.java:2: error: expected public InterfaceTest(){ ^ 1 error
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
367 Views
The super keyword is similar to this keyword. Following are the scenarios where a super keyword is used. It is used to differentiate the members of superclass from the members of the subclass if they have same names. It is used to invoke the superclass constructor from the subclass. Whenever you want to call the constructor of the superclass from a method or another constructor you can do so as: Example class Person { Person(String name) { System.out.println("Hello "+ name); } } class Student ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
6K+ Views
In the process of managing files and directories in Python, there are often situations where you need to obtain a directory listing sorted by creation date. The task of sorting files and directories by their creation timestamps can be beneficial for various purposes, such as analyzing the most recently added files or organizing data based on chronological order. Python has several methods and techniques to achieve this goal effectively and efficiently. By making use of the "os" module, the "pathlib" module, or third−party libraries, you can effortlessly obtain a sorted directory listing based on creation date. In this exhaustive article, ... Read More
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
243 Views
You can declare an array just like a variable −int myArray[];You can create an array just like an object using the new keyword −myArray = new int[5];You can initialize the array by assigning values to all the elements one by one using the index −myArray [0] = 101; myArray [1] = 102;You can access the array element using the index values −System.out.println("The first element of the array is: " + myArray [0]); System.out.println("The first element of the array is: " + myArray [1]); Alternatively, you can create and initialize an array using the flower braces ({ }): Int [] myArray = {10, 20, 30, 40, 50}
![Sarika Singh](https://www.tutorialspoint.com/assets/profiles/502778/profile/60_2211036-1660719373.jpg)
38K+ Views
A portable method of interacting with the operating system is offered through the OS Python Module. The module, which is a part of the default Python library, contains tools for locating and modifying the working directory. The following contents are described in this article. How to obtain the current working directory: os.getcwd() Changing the current working directory: os.chdir() The __file__ function returns the path to the current script file (.py). Getting the current working directory- os.getcwd() The function os.getcwd() returns as a string str the absolute path to Python's current working directory. "Get current working directory" (getcwd) refers ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
430 Views
When working with files and directories in Python, it's a crucial point to distinguish between regular files and directories. Knowing the type of each file is most essential for implementing different file handling operations, such as reading, writing, or navigating through directory structures. Python makes available several methods and techniques to determine if a given path points to a directory or a regular file. By utilizing the "os" module, the "pathlib" module, or other specialized functions, you can easily differentiate between these two types and perform the necessary operations accordingly. In this exhaustive article, we will explore different methods to ... Read More
![varma](https://www.tutorialspoint.com/assets/profiles/13568/profile/60_26300-1512638592.jpg)
2K+ Views
Default constructors in Java:A constructor initializes an object when it is created. It has the same name as its class and is syntactically similar to a method. However, constructors have no explicit return type. There are two types of constructors namely −parameterized constructors − Constructors with arguments.no-arg constructors − Constructors without arguments.Example Live Demopublic class Sample{ int num; Sample(){ num = 100; } Sample(int num){ this.num = num; } public static void main(String args[]){ System.out.println(new Sample().num); System.out.println(new Sample(1000).num); } }Output100 1000Default ConstructorIt ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
2K+ Views
When it comes to file operations in Python, adhering to best practices is crucial to ensure the security and integrity of your data. Mishandling files can lead to data corruption, resource leaks, and even security vulnerabilities. This article aims to delve into the best practices for safely opening and closing files in Python, accompanied by five illustrative code examples with stepwise explanations to enhance your understanding. Utilizing the 'with' Statement Python offers a convenient approach to opening and closing files using the 'with' statement. The 'with' statement guarantees automatic closure of the file once the code block inside ... Read More