System class - Basic Concept in java, Java programmers must know it
explain System.out.println();
System is a final class in java , we are using class name to access out (which is a reference variable of PrintStream class) that means out is a static member of System class.
so System.out returns us the PrintStream object so following line of code looks different but it is valid is valid
PrintStream p1 = System.out;
println(char[] a) is a non static method inside PrintStream class whose job is to print the passed data.
by default PrintStream object points to console , so System.out.println("data"); prints data on the console.
System.out.println("data"); is same as p1.println("data");
Check your knowledge now
main(){
PrintStream p1 = new PrintStream("stdout.log");
p1.println("hello");
System.out.println("world");
}
Based on the above knowledge what will be the output ?
explain System.out.println();
System is a final class in java , we are using class name to access out (which is a reference variable of PrintStream class) that means out is a static member of System class.
so System.out returns us the PrintStream object so following line of code looks different but it is valid is valid
PrintStream p1 = System.out;
println(char[] a) is a non static method inside PrintStream class whose job is to print the passed data.
by default PrintStream object points to console , so System.out.println("data"); prints data on the console.
System.out.println("data"); is same as p1.println("data");
Check your knowledge now
main(){
PrintStream p1 = new PrintStream("stdout.log");
p1.println("hello");
System.out.println("world");
}
Based on the above knowledge what will be the output ?
No comments:
Post a Comment