- 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 2620 Articles for Java
11K+ Views
Single Level inheritance - A class inherits properties from a single class. For example, Class B inherits Class A.Example Live Democlass Shape { public void display() { System.out.println("Inside display"); } } class Rectangle extends Shape { public void area() { System.out.println("Inside area"); } } public class Tester { public static void main(String[] arguments) { Rectangle rect = new Rectangle(); rect.display(); rect.area(); } }OutputInside display Inside areaHere Rectangle class inherits Shape class and can execute two methods, display() and area() as shown.
632 Views
Using CLASSPATH, you can load any classes at runtime.Like the .java source files, the compiled .class files should be in a series of directories that reflect the package name. However, the path to the .class files does not have to be the same as the path to the .java source files. You can arrange your source and class directories separately, as −\sources\com\apple\computers\Dell.java \classes\com\apple\computers\Dell.classBy doing this, it is possible to give access to the classes directory to other programmers without revealing your sources. You also need to manage source and class files in this manner so that the compiler and the ... Read More
825 Views
Subpackages are similar to sub-directories. Consider an example. The company had a com.apple.computers package that contained a Dell.java source file, it would be contained in a series of subdirectories like this −....\com\apple\computers\Dell.javaAt the time of compilation, the compiler creates a different output file for each class, interface, and enumeration defined in it. The base name of the output file is the name of the type, and its extension is .class.For example −// File Name:Dell.java package com.apple.computers; public class Dell { } class Ups { }Now, compile this file as follows using -d option −$javac -d.Dell.javaThe files will be compiled as ... Read More
480 Views
You can understand it using an example where a Boss class is defined in payroll package.package payroll; public class Boss { public void payEmployee(Employee e) { e.mailCheck(); } }if the Employee class is not in the payroll package? The Boss class must then use one of the following techniques for referring to a class in a different package.The fully qualified name of the class can be used. For example −payroll.EmployeeThe package can be imported using the import keyword and the wildcard (*). For example −import payroll.*;The class itself can be imported using the import keyword. ... Read More
5K+ Views
You can understand it using an example where a Boss class is defined in payroll package.package payroll; public class Boss { public void payEmployee(Employee e) { e.mailCheck(); } }if the Employee class is not in the payroll package? The Boss class must then use one of the following techniques for referring to a class in a different package.The fully qualified name of the class can be used. For example −payroll.EmployeeThe package can be imported using the import keyword and the wild card (*). For example −import payroll.*;The class itself can be imported using the import ... Read More
26K+ Views
Let us look at an example that creates a package called animals. It is a good practice to use names of packages with lower case letters to avoid any conflicts with the names of classes and interfaces.Following package example contains interface named animals −/* File name : Animal.java */ package animals; interface Animal { public void eat(); public void travel(); }Now, let us implement the above interface in the same package animals −package animals; /* File name : MammalInt.java */ public class MammalInt implements Animal { public void eat() { System.out.println("Mammal eats"); } ... Read More
4K+ Views
Let us look at an example that creates a package called animals. It is a good practice to use names of packages with lower case letters to avoid any conflicts with the names of classes and interfaces.Following package example contains interface named animals −/* File name : Animal.java */ package animals; interface Animal { public void eat(); public void travel(); }Now, let us implement the above interface in the same package animals −package animals; /* File name : MammalInt.java */ public class MammalInt implements Animal { public void eat() { System.out.println("Mammal eats"); } ... Read More
723 Views
No. Java constructor cannot return a value. If required, just create a method which calls the required constructor and returns the required value. See the example below.public class Tester { public Tester(){} public static Tester getInstance(){ Tester tester = new Tester(); return tester; } }
636 Views
Questions related to Java exception handling are most frequent during interviews for many companies and even in exams. One such question that an interviewer might ask is whether there is a case when the finally block does not execute in Java. We will try to find the answer to this question in the simplest way possible. In general, the finally block is designed to execute regardless of whether an exception is thrown or handled in the try-catch blocks. Is there a case when finally block does not execute in Java? Before moving to the question, it is necessary to discuss ... Read More
To Continue Learning Please Login
Login with Google