Q:
Java find output programs (this Keyword) | set 1
belongs to collection: Java find output programs
Java find output programs
- Java find output programs (Data Types) | set 1
- Java find output programs (Data Types) | set 2
- Java find output programs (Data Types) | set 3
- Java find output programs (Operators) | set 1
- Java find output programs (Operators) | set 2
- Java find output programs (Operators) | set 3
- Java find output programs (if else) | set 1
- Java find output programs (if else) | set 3
- Java find output programs (switch case) | set 1
- Java find output programs (switch case) | set 2
- Java find output programs (switch case) | set 3
- Java find output programs (Loops) | set 1
- Java find output programs (Loops) | set 2
- Java find output programs (Loops) | set 3
- Java find output programs (Arrays) | set 1
- Java find output programs (Arrays) | set 2
- Java find output programs (Arrays) | set 3
- Java find output programs (this Keyword) | set 1
- Java find output programs (final Keyword) | set 1
- Java find output programs (final Keyword) | set 2
- Java find output programs (static Keyword) | set 1
- Java find output programs (static Keyword) | set 2
- Java find output programs (Parameter Passing) | set 1
- Java find output programs (Class and Objects) | set 1
- Java find output programs (Class and Objects) | set 2
- Java find output programs (Class and Objects) | set 3
- Java find output programs (Constructor & Destructor) | set 1
- Java find output programs (Constructor & Destructor) | set 2
- Java find output programs (Constructor & Destructor) | set 3
- Java find output programs (Inheritance) | set 1
- Java find output programs (Inheritance) | set 2
- Java find output programs (Inheritance) | set 3
- Java find output programs (Interface) | set 1
- Java find output programs (Interface) | set 2
- Java find output programs (Interface) | set 3
- Java find output programs (Overloading) | set 1
- Java find output programs (Overloading) | set 2
- Java find output programs (Overriding) | set 1
- Java find output programs (Overriding) | set 2
- Java find output programs (Overriding) | set 3
- Java find output programs (Exception Handling) | set 1
- Java find output programs (Exception Handling) | set 2
- Java find output programs (Exception Handling) | set 3
- Java find output programs (Enumeration) | set 1
- Java find output programs (Enumeration) | set 2
- Java find output programs (Autoboxing & Unboxing) | set 1
- Java find output programs (Autoboxing & Unboxing) | set 2
- Find output programs (Java String class)
- Find Output of Java program - 1 (Mixed topics)
- Find Output of Java program - 2 (Mixed topics)
- Java find output programs (if else) | set 2
Answer Question 1:
Output:
Explanation:
In the above program, we created a class Sample that contains data members val1 and val2, and we defined a constructor and method display() inside the Sample class.
In the constructor of Sample class, here val1 and val2 are data members and also a parameter of the constructor. Here we used "this" object, which is used to differentiate data members and parameters. "this" object is used with data members and we can use local parameters directly without using "this" object.
Answer Question 2:
Output:
Explanation:
In the above program, we created a class Sample that contains static data members val1 and val2, and we defined a constructor and method display() inside the Sample class.
In the constructor of Sample class, here val1 and val2 are data members and also a parameter of the constructor. Here, we used "this" object, which is used to differentiate data members and parameters. "this" object is used with data members and we can use local parameters directly without using "this" object.
Answer Question 3:
Output:
Explanation:
The above program will generate a compile-time error because we cannot methods of a class like this,
S.fun1().fun2().fun3();
To call methods like the above statements we need to implement a cascaded method call using "this" object.
Answer Question 4:
Output:
Explanation:
In the above program, we created a Sample class that contains three method fun1(), fun2(), and fun3(). All three methods return the object of the Sample class using "this" object. Here we implemented a cascaded method call,
S.fun1().fun2().fun3();
As we know that every method call requires an object, in the above method every method returns an object that's why we are able to call methods in a cascaded manner.
Answer Question 5:
Output:
Explanation:
The above program will generate a syntax error because fun1() is a static method, and a static method cannot return reference of the object.
need an explanation for this answer? contact us directly to get an explanation for this answer