- Notifications
You must be signed in to change notification settings - Fork1
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletionsObjectAndClass.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.