+ 1
can someone explain please?
How does passing an Object (class name) as a parameter in methods and lists work? and what does it do , and allow me to do? and how i know when to use it?
6 Réponses
+ 2
Hey yahel According To Me You’re Confused In Oops Concepts So Lemme Give Brief Introduction Of Two Of These Oops Concepts That You Mentioned :
1. Class
2. Objects
So What’s Class So Class Is Collection Of Objects And The Objects Are Single Single Entity.
Suppose That You Are Student Of Grade 10 So All The Students Together Consists A Class But If I Wanna Talk About Single Entity Then I Can Check It Using Object.
Now How Class And Object Works
As I Told You Class In A Collection Of Multiple Objects So With The Help Of Object We Can Fill Our Class.
May Be With This Example You Can Understand Lil About Classes And Objects.
+ 2
Okay Okay yahel I Was Lil Confused Initially About What You Asked But Now I Understood Your Questions So Here Is The Best Explanations Of Your Query :
https://www.google.co.in/amp/s/www.geeksforgeeks.org/passing-and-returning-objects-in-java/amp/
+ 2
Glad To Help You Bro yahel
+ 1
Ryan Daniel I understand the concept of Classes and all of that but look what I asked at the question... passing object as a parameter..
+ 1
if a method gets an object it can work with this object. An object can store much information of different types.
public class Program {
public static void main(String[] args) {
var p = new Program();
Person person = new Person("John", "Doe");
p.printName(person);
}
void printName(Person person){
System.out.println(person.firstName +" "+ person.lastName);
} }
class Person {
String firstName, lastName;
Person(String firstName, String lastName) {
this.firstName=firstName;
this.lastName =lastName;
} }
+ 1
Ryan Daniel thanks!