1st UNIT.pdf
1st UNIT.pdf
1. llustrate constructors and write various types of constructors with an example program.
Solution:
2
4
5
2. Discuss Data Type in java with example program.
Solution:
6
7
8
3. Outline OOPS concepts.
Solution:
9
10
4. Explain various uses of “this” keyword with an example program.
Solution:
11
1) this: to refer current class instance variable
The this keyword can be used to refer current class instance variable. If there is ambiguity
between the instance variables and parameters, this keyword resolves the problem of
ambiguity.
class Student{
int rollno;
String name;
float fee;
Student(int rollno,String name,float fee){
this.rollno=rollno;
this.name=name;
this.fee=fee;
}
void display(){System.out.println(rollno+" "+name+" "+fee);}
}
class TestThis2{
12
3) this: to pass as an argument in the method
The this keyword can also be passed as an argument in the method. It is mainly used in the
event handling. Let's see the example:
14
5. Java Features / Java Buzz words.
Solution:
6. Explain the different Visibility modifiers in Java. / Explain the different access modifiers in
Java.
Solution :
17
20