Maruthi Krishna has Published 951 Articles

How to make an object completely encapsulated in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:02:51

288 Views

The process of wrapping up the data and, the code acting on the data together is known as encapsulation. This is a protective mechanism where we hide the data of one class from (an object of) another.Since, variables hold the data of a class to encapsulate a class you need ... Read More

Does java support hybrid inheritance?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:01:48

2K+ Views

Inheritance is a relation between two classes where one class inherits the properties of the other class. This relation can be defined using the extends keyword as −public class A extends B{ }The class which inherits the properties is known as sub class or, child class and the class whose properties ... Read More

Can we extend interfaces in Java? Explain?

Maruthi Krishna

Maruthi Krishna

Updated on 30-Jun-2020 15:17:30

782 Views

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Just like classes you can extend one interface from another using the extends keyword as shown below −interface ArithmeticCalculations{    public abstract int addition(int a, int b);    public abstract ... Read More

How to write/declare an interface inside a class in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:45:53

736 Views

An interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a type should be you can define an interface.To create an object of this type you need to implement this interface, provide ... Read More

Can we write an interface without any methods in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:44:24

2K+ Views

Yes, you can write an interface without any methods. These are known as marking interfaces or, tagging interfaces.A marker interface i.e. it does not contain any methods or fields by implementing these interfaces a class will exhibit a special behavior with respect to the interface implemented.ExampleConsider the following example, here ... Read More

What is a remote interface in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:43:24

3K+ Views

A Remote interface is available in the java.rmi package it is a marking/tagging interface, it is used with remote method invocation(RMI).RMI is a mechanism that allows an object residing in one system (JVM) to access/invoke an object running on another JVM.To it is a marking interface, to mark an object ... Read More

How to format a string to date in as dd-MM-yyyy using java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:42:48

15K+ Views

The java.text package provides a class named SimpleDateFormat which is used to format and parse dates in required manner (local).Using the methods of this class you can parse String to Date or, format Date to String.Parsing String to DateYou can parse a given String to Date object using the parse() ... Read More

What happens if the subclass does not override abstract methods in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:39:48

5K+ Views

A method which does not have body is known as abstract method. It contains only method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();To use an abstract method, you need to inherit it by extending its class and provide implementation to it.A class which contains ... Read More

Can we declare the variables of a Java interface private and protected?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:37:41

3K+ Views

Interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Private fields of an interfaceIf the fields of the interface are private, you cannot access them in the implementing class.If you try to declare the fields of an interface private, a ... Read More

Can we implement one interface from another in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:35:20

337 Views

No, we cannot implement one interface from another you can just extend it using the extends keyword as −interface ArithmeticCalculations{    public abstract int addition(int a, int b);    public abstract int subtraction(int a, int b); } interface MathCalculations implements ArithmeticCalculations{    public abstract double squareRoot(int a);    public abstract ... Read More

Advertisements