Anukul Java 3
Anukul Java 3
Anukul Java 3
1) What do you mean by final variable in java? explain it's types with
examples?
=> In Java, a final variable is one whose value cannot be changed once it has been
assigned. There are three types of final variables:
a) Final Variables: These are variables declared with the final keyword and are
initialized only once. Once initialized, their value cannot be modified
System.out.println(message);
c) Final Fields: These are fields in a class marked as final. They must be
initialized either at the time of declaration or within the constructor and cannot be
modified thereafter.
Circle(int radius) {
this.radius = radius;
}
NAME- Anukul Kumar
=> In Java, super is a keyword used to refer to the immediate parent class object,
accessing its methods and variables, and invoking its constructor. On the other
hand, extends is a keyword used to create a subclass that inherits properties and
behaviors from a superclass, establishing an "is-a" relationship between classes.
4) What is the difference between compile time polymorphism and run time
polymorphism?
NAME- Anukul Kumar
=>
In Compile time Polymorphism, the call is In Run time Polymorphism, the call is not
resolved by the compiler. resolved by the compiler.
It is also known as Static binding, Early It is also known as Dynamic binding, Late
binding and overloading as well. binding and overriding as well.
=> In Java, the heap memory is a region of the computer's memory that is allocated
for dynamic memory allocation. It's where objects and their associated data are
stored during the execution of a Java program. Unlike the stack memory, which is
used for static memory allocation and method execution, the heap memory is used
for storing objects created at runtime.
6) What is the difference between serial garbage collector and parallel garbage
collector?
=>
Inheritance program:
class Father{
Father(){
System.out.println("Fathers's place");
}
Father(int a){
System.out.println("Param father "+a);
}
int Father(int a, int b){
return a+b;
}
}
class Son1 extends Father{
Son1(){
super(5);
System.out.println("Son's place");
}
}
Son's place
35