Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

object, class and inheritance#1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ultron-coder merged 3 commits intoultron-coder:mainfromismailfaris19:main
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletionsObjectAndClass.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
package oopsConcepts;

public class ObjectAndClass {

int employeeId;
String employeeName;

public ObjectAndClass() {
super();
}

public ObjectAndClass(int employeeId, String employeeName) {
super();
this.employeeId = employeeId;
this.employeeName = employeeName;
}

public void methodInitializer(int id, String name) {
employeeId = id;
employeeName = name;
}

public void methodForAnonymousObject() {
System.out.println("Employee ID: "+employeeId+" is updated successfully.");
}

public void display() {
System.out.println("Employee ID: "+employeeId+" and Employee Name: "+employeeName+" is updated successfully.");
}


public static void main(String[] args) {

ObjectAndClass oc = new ObjectAndClass();

//through variable reference

oc.employeeId = 1608;
oc.employeeName = "Ismail";
oc.display();

//through method reference

oc.methodInitializer(1608, "Faris");
oc.display();

//through constructor reference

ObjectAndClass oac = new ObjectAndClass(1608, "Ismail Faris");
oac.display();

//anonymous object

new ObjectAndClass(1608, "Faris").methodForAnonymousObject();

}

}
135 changes: 135 additions & 0 deletionsTypesOfInheritance.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
package oopsConcepts;

//IS-A Relationship

//Single Inheritance

//class ParentClass{
//int i = 5;
//int j = 10;
//void sum() {
//int total = i + j;
//System.out.println(total);
//}
//}
//
//class SubClass extends ParentClass{
//void display() {
//System.out.println("problem solved");
//}
//}
//
//public class TypesOfInheritance {
//
//public static void main(String[] args) {
//
//SubClass ps = new SubClass();
//ps.sum();
//ps.display();
//}
//
//}

//Multi Level Inheritance with method overloading and overriding concept

//class ParentClass{
//int i = 5;
//int j = 10;
//void sum() {
//int total = i + j;
//System.out.println(total);
//}
//}
//
//class SubClassOne extends ParentClass{
//void display() {
//System.out.println("From One");
//}
//void display(int k) {
//i = k;
//}
//}
//
//class SubClassTwo extends SubClassOne{
//void display() {
//super.display();
//super.display(5);
//System.out.println("From Two");
//}
//}
//
//public class TypesOfInheritance {
//
//public static void main(String[] args) {
//
//SubClassTwo ps = new SubClassTwo();
//ps.sum();
//ps.display();
//}
//
//}

//Hierarchical Inheritance

//class ParentClass{
//int i = 5;
//int j = 10;
//void sum() {
//int total = i + j;
//System.out.println(total);
//}
//}
//
//class SubClassOne extends ParentClass{
//void display() {
//System.out.println("From One");
//}
//}
//
//class SubClassTwo extends ParentClass{
//void display() {
//System.out.println("From Two");
//}
//}
//
//public class TypesOfInheritance {
//
//public static void main(String[] args) {
//
//SubClassOne so = new SubClassOne();
//so.sum();
//so.display();
//
//SubClassTwo st = new SubClassTwo();
//st.sum();
//st.display();
//}
//}

//HAS-A Relationship

class ParentClass{
int i = 5;
int j = 10;
public int sum() {
int total = i + j;
return total;
}
}

class SubClassOne{
ParentClass pc;
public void display() {
pc = new ParentClass();
int k = pc.sum();
int multiply = k * k;
System.out.println(multiply);
}
}

public class TypesOfInheritance {

public static void main(String[] args) {
new SubClassOne().display();
}
}

[8]ページ先頭

©2009-2025 Movatter.jp