Posts

Input and output in java

Image
Input and Output (IO) are mainly used concepts in java real time applications to share objects from one place to another. Input represents data given to a program and output represents data displayed as a result of program. We are already familiar with the following two statements to display the output. 1 2 System . out . print (); System . out . println ();                 Both of the statements are used to show the output on the screen. The difference between these two is that print() method keeps cursor in the same line after displaying the output and println() throws cursor to the next line after displaying the result. Example to show the differences between print() and println() methods: 1 2 3 4 5 6 7 8 9 10 public class Sysout { public static void main ( String [] args ){ int a , b ; a = 10 ; b = 15 ; c...

Polymarphism interview questions and answers in java

Polymorphism is one of the Oops concept and mostly used feature in java. The ability of an object to take more than one form is called Polymorphism. The most common use of polymorphism in OOPs occurs when a parent class reference is used to refer to a child class object.         It is impossible to know that the only possible way to access the object is through a reference variable. A reference variable can be of  only one type. Once declared, the type of the reference variable cannot be changed.         A reference variable can refer to any object of its declared type or any subtype of its declared type. A reference variable can be declared as a class or interface. Ex: Let's take a look into the below example 1 2 3 4 5 interface Vehicle {} class Mileage {} public class Car extends Mileage implements Vehicle {} see the implementation of the above example, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

Object Oriented Programming in java

Object Oriented Program or Oops is a technique to create programs based on the real world object. In the Oops programming model programs are organized around objects and data rather than actions and logic. What is Oops?           An Object Oriented Programming organizes a program around its data, i.e., objects and a set of well defined interfaces to that data. An object-oriented programming can be characterized as data controlling access to code. Why Oops?           Object Oriented Programming enables programmers define not only the data, but also its associated behaviors that can be applied to the data. It also enables programmers to create relationship between one object and another. For example, Objects can inherit characteristics from other objects. To understand the importance of Oops first we need to understand the problem with Procedural...