Java Oops
Java Oops
class Oops {
st.name="Vijay";
st.roll_num=55;
st.marks=85.6;
st.greet();
class Student{
int roll_num;
String name;
double marks;
Student(){}
this.roll_num=roll_num;
this.name=name;
this.marks=marks;
void greet(){
Final Keyword
In Java, the final keyword is a modifier that can be applied to variables, methods, and classes,
and it serves different purposes depending on where it is used.
1.Final Variables: When a variable is declared as final, it means that its value cannot be changed once it
has been assigned.
always inilized when declaired => final int b;// cause error
2. Final Methods
A method declared as final cannot be overridden by subclasses. This is useful when you want to prevent
changes to a method's implementation.
class Parent {
3. Final Classes
A class declared as final cannot be subclassed. This is useful for creating immutable classes or for
security reasons.
// Class implementation
Static Method
import java.util.*;
class Oops {
greet();
void greet(){
}// error due static method can only access static data/method;
static method can access only static method or data, but we can access static member method or data
inside the non-static member;
Super Keyword
import java.util.*;
class Animal{
int a=10;
void walk(){
Animal(){
System.out.println("animal is created");
}
class Dog extends Animal{
int a=15;
Dog(){
super();
System.out.println("dog is created");
void walk(){
super.walk();
void valueA(){
System.out.println(a);
System.out.println(super.a);
d.walk();
d.valueA();
Polymorphisms
1.Complile Time Polymorphisms achieved by Method Overloading
class Bike{
return a+b;
return a+b+c;
public class A{
System.out.println(b.run(2,3));
System.out.println(b.run(2,3,4));
When a method that is present in both parent and child has same name, return type, type of parameter
and number of parameters is same but they are in different class or body;
import java.util.*;
class Shape{
void draw(){
System.out.println("drawing...");
}
class Rectangle extends Shape{
void draw(){
System.out.println("drawing rectangle...");
super.draw();
public class A{
b.draw();
Interface
1.Multiple inheritance
public interface Engine {
void start ();
void stop ();
}
interface Fun {
void song ();
void stop ();
}
interface Break {
void acc ();
}
Generic
import java.util.*;
class Car<E,V>{
E id;
V name;
this.id=id;
this.name=name;
void solve(){
Car<Integer,String>car=new Car<>(2,"Vijay");
car.solve();