Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint
Cover Image
Cover Image
Drag to reposition
Contributed Answers

Override the toString() method in a Java Class

Answered on 19th Feb, 2019, 0 Views

A string representation of an object can be obtained using the toString() method in Java. This method is overridden so that the object values can be returned. A program that demonstrates this is given as follows:  Live Demo , , Now let us understand the above program. The Student class is created with data members rno, name. The constructor Student() initializes rno and name. The overr.....

Demonstrate Static Import in Java

Answered on 15th Feb, 2019, 0 Views

Static import is a feature that was introduced in Java version 5 and above. It means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static. A program that demonstrates this in Java is given as follows:  Live Demo , , Now let us understand the above program. The System class is not required in System.out.printl.....

Why Abstract Class is used in Java?

Answered on 15th Feb, 2019, 0 Views

A class is an abstract class if it contains at least one abstract method. It can contain other non-abstract methods as well. A class can be declared as abstract by using the abstract keyword. Also, an abstract class cannot be instantiated. A program that demonstrates an abstract class in Java is given as follows:  Live Demo , ,

Why Protected access modifier used in Java?

Answered on 15th Feb, 2019, 0 Views

The data members and methods of a class can be accessed from the same package or sub-classes in a different package if they are specified with the protected access modifier. The keyword protected is used to specify this modifier. A program that demonstrates the protected access modifier in Java is given as follows:  Live Demo , , Now let us understand the above program. The class A has.....

Recursive factorial method in Java

Answered on 15th Feb, 2019, 0 Views

The factorial of any non-negative integer is basically the product of all the integers that are smaller than or equal to it. The factorial can be obtained using a recursive method. A program that demonstrates this is given as follows:  Live Demo , , Now let us understand the above program. The method fact() calculates the factorial of a number n. If n is less than or equal to 1, it ret.....

Why do we use import statement in Java? Where it should be included in the class?

Answered on 15th Feb, 2019, 0 Views

The import statement can be used to import an entire package or sometimes import certain classes and interfaces inside the package. The import statement is written before the class definition and after the package statement(if there is any). Also, the import statement is optional. A program that demonstrates this in Java is given as follows:  Live Demo , , Now let us understand the abo.....

Using run-time polymorphism in Java

Answered on 15th Feb, 2019, 0 Views

A single action can be performed in multiple ways using the concept of polymorphism. Run-time polymorphism can be performed by method overriding. The overridden method in this is resolved at compile time. A program that demonstrates run-time polymorphism in Java is given as follows:  Live Demo , ,

Role of super Keyword in Java Inheritance

Answered on 15th Feb, 2019, 0 Views

Parent class objects can be referred to using the super keyword in Java. It is usually used in the context of inheritance. A program that demonstrates the super keyword in Java is given as follows:  Live Demo , , Now let us understand the above program. The class A contains a data member a and constructor A(). The class B uses the extends keyword to derive from class A. It also contain.....

Static Nested Classes in Java

Answered on 15th Feb, 2019, 0 Views

A nested class in Java is of two types i.e. Static nested class and Inner class. A static nested class is a nested class that is declared as static. A nested nested class cannot access the data members and methods of the outer class. A program that demonstrates a static nested class is given as follows:  Live Demo , , Now let us understand the above program. The class Class1 is the out.....

Reference static field after declaration in Java

Answered on 15th Feb, 2019, 0 Views

The static field variable is a class level variable and it belongs to the class not the class object. So the static field variable is common to all the class objects i.e. a single copy of the static field variable is shared among all the class objects. A program that demonstrates referencing the static field variable after declaration is given as follows:  Live Demo , , Now let us unde.....

loader
Advertisements
Contribution

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.