Unit 1 JAVA
Unit 1 JAVA
// Methods
public void sum() { System.out.println(a + b); }
Output
3
-1
Employee_name = n;
Employee_salary = p;
}
}
// Main Method
GFG.get();
Output
import java.io.*;
class Student {
// Properties Declared
int id;
String name;
// Printing Student
System.out.println("Id:" + id);
System.out.println("Name:" + name);
class GFG {
obj.id = 1;
obj.name = "ABC";
obj.printStudent();
}
Output
Id:1
Name: ABC
1. Abstraction
// abstract class
abstract class GFG {
// abstract methods declaration
2. Encapsulation
// Encapsulation using private modifier
class Employee {
this.empid = empid;
this.ename = ename;
// Getter methods
return empid;
}
public String get_name() {
return ename;
e.set_name("John");
Output
Employee id: 78
3. Inheritance
class A {
//parent class methods
void method1(){}
void method2(){}
}
//derived class or child class or base class
void method3(){}
void method4(){}
4. Polymorphism
sleep(1000) //millis
sleep(1000,2000) //millis,nanos
Types of Polymorphism
// Parent Class
class Parent {
// Method Declared
}
// Method Overloading
}
// Child Class
@Override
}
// Main Method
obj1.func();
obj1.func(5);
obj2.func(4);
Output
Child Method 4