Introduction of Java Output Function (System.out.println())
Java use print function to display out. It can be used in two way.
- Output without new line
For this purpose we use System.out.print('desired output string'); - Output with new line
For this purpose we use System.out.println('desired output string'); - Example :
Save this file with Test.java
class CRectangle
{
private int length;
private int breadth;
CRectangle()
{
System.out.println("Class CRectangle : Default constructor called...");
length = 5;
breadth = 3;
}
CRectangle(int l, int b)
{
System.out.println("Class CRectangle : Parametrized constructor called..");
length = l;
breadth = b;
}
void setLength(int l){length = l;}
int getLength(){return length;}
void setBreadth(int b){breadth = b;}
int getBreadth(){return breadth;}
}
import java.io.*;
class Test
{
public static void main(String args[])
{
CRectangle r;
r = new CRectangle();
System.out.println("Length : " + r.getLength());
System.out.println("Breadth : " + r.getBreadth());
}
}
No comments:
Post a Comment