+ 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?

9th Aug 2020, 9:36 AM
Yahel
Yahel - avatar
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.
9th Aug 2020, 10:01 AM
Rahul Saxena
Rahul Saxena - avatar
+ 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/
9th Aug 2020, 10:42 AM
Rahul Saxena
Rahul Saxena - avatar
+ 2
Glad To Help You Bro yahel
9th Aug 2020, 10:47 AM
Rahul Saxena
Rahul Saxena - avatar
+ 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..
9th Aug 2020, 10:21 AM
Yahel
Yahel - avatar
+ 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; } }
9th Aug 2020, 10:38 AM
zemiak
+ 1
Ryan Daniel thanks!
9th Aug 2020, 10:46 AM
Yahel
Yahel - avatar